icmp sniffer with pcapy module

B

billiejoex

Hi all. The source below is a simple icmp sniffer made with pcapy.
To decode packets I'm using the EthDecoder() function that returns a
rapresentation of the packet including ICMP type, ICMP code, IP source and
IP destination.
All I need, now, is to get the ip src and ip dst only but I don't know how
to do it.
I tried to use the IPDecoder instead of EthDecoder to decode packets but
misteriously it doesn't works.
Does anybody have a good idea about how to get this values only?

Best regards

#!/usr/bin/python
### sniffer
import pcapy
from impacket.ImpactDecoder import *

def recv_pkts(hdr, data):
x = EthDecoder().decode(data)
print x

def get_int():
devs = pcapy.findalldevs()
i=0
for eth in devs:
print " %d - %s" %(i,devs)
i+=1
sel=input(" Select interface: ")
dev=devs[sel]
return dev

dev = get_int()
p = pcapy.open_live(dev, 1500, 0, 100)
p.setfilter('icmp')
print "Listening on eth: net=%s, mask=%s\n" % (p.getnet(), p.getmask())
p.loop(-1, recv_pkts)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top