Let's say our network contains a mix of Windows, Unix, and Linux machines with users adding their own Bring Your Own Device (BYOD); they may or may not support an ICMP ping. We can now construct a file with three types of common pings for our network, the ICMP, TCP, and UDP pings, in scapy_ping_collection.py:
#!/usr/bin/env python2from scapy.all import *def icmp_ping(destination): # regular ICMP ping ans, unans = sr(IP(dst=destination)/ICMP()) return ansdef tcp_ping(destination, dport): # TCP SYN Scan ans, unans = sr(IP(dst=destination)/TCP(dport=dport,flags="S")) return ansdef udp_ping(destination): # ICMP Port unreachable error from closed port ans, unans = sr(IP(dst=destination)/UDP(dport=0)) return ans
In this example, ...