You have sniffed a packet with a payload without src
attribute. If you want a quick fix for your code, write:
def fun_callback(pkt):
if hasattr(pkt.payload, "src"):
print str(pkt.payload.src)
The problem is, you don't really known what pkt.payload
will be. If you want a better fix, try something like:
def fun_callback(pkt):
if IP in pkt: print pkt[IP].src
elif IPv6 in pkt: print pkt[IPv6].src
Or better, with .sprintf()
:
sniff(prn=lambda pkt: pkt.sprintf("{IP:%IP.src%}{IPv6:%IPv6.src%}"),
filter='icmp', timeout=5))