Listen for ICMP packets in C#

Nearly 3 years later and I stumbled across http://www.codeproject.com/Articles/17031/A-Network-Sniffer-in-C which gave me enough of a hint to help me find a solution to receiving ICMP packets on Windows 7 (don’t know about Vista, which the original question was about but I suspect this solution would work). The two key points are that the socket has … Read more

ICMP sockets (linux)

Linux have a special ICMP socket type you can use with: socket(PF_INET, SOCK_DGRAM, IPPROTO_ICMP); This allows you to only send ICMP echo requests The kernel will handle it specially (match request/responses, fill in the checksum). This only works if a special sysctl is set. By default not even root can use this kind of socket. … Read more

Pinging servers in Python

If you don’t need to support Windows, here’s a really concise way to do it: import os hostname = “google.com” #example response = os.system(“ping -c 1 ” + hostname) #and then check the response… if response == 0: print hostname, ‘is up!’ else: print hostname, ‘is down!’ This works because ping returns a non-zero value … Read more