473,396 Members | 1,678 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.

icmp sniffer with pcapy module

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])
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)
Sep 9 '05 #1
0 1560

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Bob Rivers | last post by:
Hi, I was doing a research looking for Java solutions that are able to do "ping". I found old messages (and not so old ones), telling that Java was not able to do that, because the API...
0
by: Andreas Pauley | last post by:
Hi, I'd like to generate my own icmp packets from within python. Typically this would include sending an ECHO_REQUEST and checking if I get an ECHO_REPLY back. But I would also like to...
6
by: billiejoex | last post by:
Hi! I made a little, simple program that sends strings over an ICMP packet. The source here: http://billiejoex.altervista.org/a1.txt Now all I need is create a simple network sniffer able to...
2
by: billiejoex | last post by:
Hi. I'm trying to use pcapy module on Windows XP prof sp2 but it doesn't work. The example source reported on the site (http://oss.coresecurity.com/impacket/sniff.py) works only on *unix...
1
by: billiejoex | last post by:
Hi all. I noticed that with the original pcap sniffing library it is possible to listen on multiple devices by using "select()" or "poll()" function. These function aren't present in pcapy module....
0
by: Ed | last post by:
I've attached some VB.NET code I've hacked together (some taken from MS examples & newsgroup postings) that will perform a ping or IcmpSendEcho using the icmp.dll (see this for more info:...
5
by: Tom Anderson | last post by:
Hi all, This is a little function to compare two iterators: def icmp(a, b): for xa in a: try: xb = b.next()
2
by: Laurent Laporte | last post by:
hello, I'm using cvs standard module under Python 2.3 / 2.4 to read a CSV file. The file is opened in binary mode, so I keep the end of line terminator. It appears that the csv.Sniffer force...
1
by: Piotrekk | last post by:
Hi I have written piece of code to send message to my router. static void Main(string args) { Socket mySock = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Icmp); ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.