472,117 Members | 2,684 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,117 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 3194

Post your reply

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

Similar topics

13 posts views Thread by Shailesh Humbad | last post: by
1 post views Thread by Gman | last post: by
4 posts views Thread by Hans Nieser | last post: by
7 posts views Thread by D. Patrick | last post: by
10 posts views Thread by Chris Crowther | last post: by
7 posts views Thread by erikcw | last post: by
reply views Thread by leo001 | last post: by

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.