[Python] 'haslayer' function not working in scapy-python

Discussão em 'Python' iniciado por Stack, Julho 30, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to write a simple code that detect IP source address for ICMP packet in scapy, the problem is haslayer function looks not returning anything.

    from scapy.all import *

    while 1:

    pkt = sniff ( iface="eth0" , count = 1 )
    pkt.summary()

    try:
    if pkt.haslayer(IP):
    ipsrc =pkt.getlayer(IP).src
    print ipsrc

    except:
    pass


    the result is

    Ether / IP / ICMP 10.0.2.15 > 10.0.2.11 echo-request 0 / Raw
    Ether / IP / ICMP 10.0.2.15 > 10.0.2.11 echo-request 0 / Raw
    Ether / IP / ICMP 10.0.2.15 > 10.0.2.11 echo-request 0 / Raw


    So I'm not able to catch the IP source address for the ICMP request Any idea ?

    Continue reading...

Compartilhe esta Página