Skip to content

Instantly share code, notes, and snippets.

@kjseefried
Created July 15, 2014 01:13
Show Gist options
  • Save kjseefried/42b5ed02a76cd518497f to your computer and use it in GitHub Desktop.
Save kjseefried/42b5ed02a76cd518497f to your computer and use it in GitHub Desktop.
Return an ICMP unreachable to a packet. Scapy example.
# Sending ICMP HOST UNREACHABLE USING SCAPY (PYTHON TOOLS)
# Will WORK for UDP/TCP, just give the "packet" (scapy's representation)
def send_icmp_unreachable (packet):
global MYMAC
global IPGATEWAY
global INTERFACE
p = Ether(src=MYMAC, dst=packet.src)/IP(src=IPGATEWAY, dst=packet.getlayer(IP).src)
# ICMP type=3 code=1 Host Unreachable
icmp = ICMP()
icmp.type = 3
icmp.code = 1
try:
sendp(p/icmp/packet.getlayer (IP)/packet.getlayer (UDP), iface=INTERFACE)
except:
sendp(p/icmp/packet.getlayer (IP)/packet.getlayer (TCP), iface=INTERFACE)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment