Sending ICMP Packets

Andreas Pauley python-list at qbcon.com
Tue Mar 23 09:24:49 EST 2004


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 send/receive other icmp
types, like timestamp and timestamp replies.

At the moment I'm playing with the socket module:
import socket
icmp=socket.getprotobyname('icmp')
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp)

My "s" object has a sendto() method which accepts a string and an address
(according to the socket docs), but I'm not sure what the value of the
string should be.

Does anyone have some simple example code that will ping a host?

This is part of some firewall tests that I'm writing as unit tests, so if
anyone knows of tools out there that can help with firewall testing I'd
appreciate that aswell.

Regards,
Andreas





More information about the Python-list mailing list