##
Scapy
Python library to craft, send, sniff and dissect packets — stack layers with the / operator.
// notes
- Python library to craft, send, sniff & dissect packets
- RandIP() · RandMAC() · RandInt() generate random values
- sr() = send + receive · srloop() loops and prints replies
- Ideal for testing ACLs, IDS/IPS and protocol behaviour
// worked examples
from scapy.all import *
# TCP SYN scan of one port
ans, unans = sr(IP(dst="192.0.2.10")/TCP(dport=443, flags="S"), timeout=2)
for snd, rcv in ans:
print(rcv[TCP].flags) # 'SA' = open, 'RA' = closed from scapy.all import *
# ARP ping a whole subnet (who is up?)
ans, _ = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="192.168.1.0/24"), timeout=2)
for snd, rcv in ans:
print(rcv.psrc, rcv.hwsrc) from scapy.all import *
# Sniff 10 DNS packets and print a summary
sniff(filter="udp port 53", count=10, prn=lambda p: p.summary())