tcp - Python scapy show ip of the ping (echo) requests -


i want grab , print source address of ping requests. have following script:

pkt = sniff(filter="icmp", timeout =15, count = 15) if pkt[icmp].type == '8':     print pkt[ip].src 

when packet arrives script crashes

 attributeerror:'list' object has no attribute 'type' 

however on scapy console can see exist!

>>>packet=ip()/icmp()/"aaaaaa" >>>packet[icmp].type 8 >>> 

any thoughts??

i changed testing purposes (!) script following:

pkts=sniff(filter="icmp", timeout=120,count=15)  packet in pkts:     if packet.haslayer(ip) , str(packet.getlayer(ip).src)=="127.0.0.1"        print "packet arrived"            if packet.haslayer(icmp) , str(packet.getlayer(icmp).type)=="8":                 print(packet[ip].src) 

the above after doing ping:

ping localhost -c 3 

produces following awkward result:

packet arrived 127.0.0.1 packet arrived 127.0.0.1 packet arrived packet arrived packet arrived 127.0.0.1 packet arrived 127.0.0.1 packet arrived packet arrived packet arrived 127.0.0.1 packet arrived 127.0.0.1 packet arrived 

we can ignore "packet arrived" multiple times because other packets reaching host well. why see 6 times 127.0.0.1 when sent 3 echo requests ? if remove loop same results happening.

you have multiple packets can either index or iterate over:

from scapy.all import * pkts = sniff(filter="icmp", timeout =15,count=15)  packet in pkts:      if  str(packet.getlayer(icmp).type) == "8":          print(packet[ip].src) 

or using indexing forst packet:

from scapy.all import * pkts = sniff(filter="icmp", timeout =15,count=15)  if pkts  , str(pkts[0].getlayer(icmp).type) == "8":          print(pkts[0][ip].src) 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -