473,396 Members | 2,029 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,396 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 3484

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
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.