473,287 Members | 1,565 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

How to extract a Payload data and IP addresses from a captured packet

21
I'm using Pcapy and impacket module for packet sniffer.
I'm able to capture the whole data in a variable and display it.
I want extract the IP addresses , Port no's and Payload data into separate variable and display it.

code is as follows:
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. import string
  3. from threading import Thread
  4.  
  5. import pcapy
  6. from pcapy import findalldevs, open_live
  7. import impacket
  8. from impacket.ImpactDecoder import EthDecoder, LinuxSLLDecoder
  9.  
  10.  
  11. class DecoderThread(Thread):
  12.     def __init__(self, pcapObj):
  13.         datalink = pcapObj.datalink()
  14.         if pcapy.DLT_EN10MB == datalink:
  15.             self.decoder = EthDecoder()
  16.         elif pcapy.DLT_LINUX_SLL == datalink:
  17.             self.decoder = LinuxSLLDecoder()
  18.         else:
  19.             raise Exception("Datalink type not supported: " % datalink)
  20.  
  21.         self.pcap = pcapObj
  22.         Thread.__init__(self)
  23.  
  24.     def run(self):
  25.         self.pcap.loop(0, self.packetHandler)
  26.  
  27.     def packetHandler(self, hdr, data):
  28.         d = self.decoder.decode(data)
  29.     print d
  30.  
  31. def main(filter):
  32.     dev = 'eth0'
  33.     p = open_live(dev, 1500, 0, 100)
  34.     p.setfilter(filter)
  35.     print "Listening on %s: net=%s, mask=%s, linktype=%d" % (dev, p.getnet(), p.getmask(), p.datalink())
  36.     DecoderThread(p).start()
  37.  
  38. filter=' '
  39. main(filter)
How can i do that....

Thanks....
Mar 2 '09 #1
0 3357

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Shailesh Humbad | last post by:
I wrote a short page as a quick reference to c++ integer data types. Any feedback welcome: http://www.somacon.com/blog/page11.php
1
by: Robert Marshall | last post by:
Hi all, Hoping someone can help me with an issue I'm having. I'm using AccessXP to create a database of U.S. Census records. After keying the data in, I decided to run a query to create a...
1
by: Gman | last post by:
I have a friend that asked me to help him with an access problem. I'm not access savy. The problem, he has captured data on a club members. He has a club member report that members can select to...
4
by: Hans Nieser | last post by:
Hi, I'm pretty new to C#, and recently I have been experimenting with sockets. However, I can't find a nice way (I've been fiddling with for-loops to no avail) to parse the data that comes in...
7
by: D. Patrick | last post by:
I need to duplicate the functionality of a java applet, and how it connects to a remote server. But, I don't have the protocol information or the java source code which was written years ago. ...
10
by: Chris Crowther | last post by:
Hi All, Does anyone know if it's possible to grab the raw payload data from a TCP packet, using .NET (C# to be exact). I'm writing a piece of software that communicates to a networked device...
2
by: missolsr | last post by:
hi, I am using jpcap to capture OLSR topology control (udp) packets. Does anyone know how to extract data (the way ethereal does it) from the olsr packet? There are methods to extract data...
7
by: erikcw | last post by:
Hi all, I'm trying to extract zip file (containing an xml file) from an email so I can process it. But I'm running up against some brick walls. I've been googling and reading all afternoon, and...
45
by: Dennis | last post by:
Hi, I have a text file that contents a list of email addresses like this: "foo@yahoo.com" "tom@hotmail.com" "jerry@gmail.com" "tommy@apple.com" I like to
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.