Created
July 15, 2014 01:13
-
-
Save kjseefried/42b5ed02a76cd518497f to your computer and use it in GitHub Desktop.
Return an ICMP unreachable to a packet. Scapy example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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