I use the following code to generate ICMP requests, get the results back and also get the round trip time for each request.
It works fine, except when I add icmp_type
to the packet header. As long as I pass icmp_type
, the code stops working.
I appreciate any help on this.
def icmp_ping(host, icmp_code, icmp_type=None, count=2):
packet = Ether() / IP(dst=host, proto=1) / ICMP(code=icmp_code)
t = 0.0
for x in range(count):
ans, unans = srp(packet, iface="h1-eth0", verbose=0)
rx = ans[0][1]
tx = ans[0][0]
delta = rx.time - tx.sent_time
print "Ping:", delta * 1000
print packet.summary()
t += (delta * 1000)
return (t / count)
if __name__ == "__main__":
for i in range(6):
total = icmp_ping('10.0.0.3', i)
print "TOTAL", total