scapy icmp samles
 
Send a simple Echo Request and wait for the answer and display it.  
# set target ip and icmp-data
ip_target = "192.168.2.200"
data = "Space for Rent!"
# define ip and icmp
ip = IP()
icmp = ICMP()
# creat ip + icmp parameters
ip.dst = ip_target
icmp.type = 8
icmp.code = 0

a = sr1(ip/icmp/data)
a.summary()
 
and the new Scapy Ping Command (function)  
def ping(host, count=3):
  packet = IP(dst=host)/ICMP()
  for x in range(count):
     ans = sr1(packet)
     ans.show2()

ping ("192.168.2.200",4)
 
for sending all types and codes of icmp, simply build 2 for loops and send the packet. On the Taget side, you can sniff, what packet's are recived.  
# set target ip 
ip_target = "192.168.2.201"
# define ip and icmp 
ip = IP()
icmp = ICMP()
# set the destinaion IP to the target
ip.dst = ip_target
# create 2 casade loops for sending the icmp packet
for i_type in range(0,256):
  for i_code in range(0,256):
    icmp.type = i_type
    icmp.code = i_code
    print i_type,i_code
    send(ip/icmp)


 

scapy special icmp
 
send icmp type 3 and code 4 packtes back to the a sender for reduce the MTU  
pmtu.py -> manipulate the MTU size
mtu_flood.py -> create routing entrys on a Windows XP System

(c) 2009 by packetlevel.ch / last update: 07.11.2009