By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,271 Members | 1,722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,271 IT Pros & Developers. It's quick & easy.

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

P: 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
Share this question for a faster answer!
Share on Google+

Post your reply

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