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:
How can i do that....
Thanks....
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:
Code:
import sys
import string
from threading import Thread
import pcapy
from pcapy import findalldevs, open_live
import impacket
from impacket.ImpactDecoder import EthDecoder, LinuxSLLDecoder
class DecoderThread(Thread):
def __init__(self, pcapObj):
datalink = pcapObj.datalink()
if pcapy.DLT_EN10MB == datalink:
self.decoder = EthDecoder()
elif pcapy.DLT_LINUX_SLL == datalink:
self.decoder = LinuxSLLDecoder()
else:
raise Exception("Datalink type not supported: " % datalink)
self.pcap = pcapObj
Thread.__init__(self)
def run(self):
self.pcap.loop(0, self.packetHandler)
def packetHandler(self, hdr, data):
d = self.decoder.decode(data)
print d
def main(filter):
dev = 'eth0'
p = open_live(dev, 1500, 0, 100)
p.setfilter(filter)
print "Listening on %s: net=%s, mask=%s, linktype=%d" % (dev, p.getnet(), p.getmask(), p.datalink())
DecoderThread(p).start()
filter=' '
main(filter)
Thanks....