derCollegeblock
derCollegeblock

Reputation: 11

Why does scapy give me an socket error when I try to start recording the network stream?

These are the two main functions for scapy:

def spck_clbk(packet):
    global ip_cnt
    if IP in packet:
        save_pkDATA(packet)
        ip_cnt += 1
        ip_src = packet[IP].src
        ip_trg = packet[IP].dst
        print(f"{ip_cnt}. IP Source found.... {ip_src}")
        print(f"Target IP spottet... ( -_•)︻デ═一 {ip_trg} ")
    if TCP in packet:
        print(f"TCP Paket: {packet[IP].src}:{packet[TCP].sport} -> {packet[IP].dst}:{packet[TCP].dport}")

    if UDP in packet:
        print(f"UDP Packet: {packet[UDP].src}:{packet[UDP].sport} -> {packet[IP].dst}:{packet[UDP].dport}")
    if ICMP in packet:
        print(f"ICMP Paket: {packet[IP].src} -> {packet[IP].dst}")
def str_sn(interface):
    print(f"Sniffing on {interface}....")
    sniff(iface = interface, prn = spck_clbk, store =0, filter="ip", timeout=5)

I tried to use the IP filter and anything, but the Error I get is always the same:

WARNING: Socket <scapy.arch.libpcap.L2pcapListenSocket object at 0x000002006B05BF90> failed with 'src'. It was closed.

Any ideas?

Upvotes: 1

Views: 58

Answers (1)

artisignal
artisignal

Reputation: 401

What instantly meets the eye is that there might be a typo in the IP address specifier:

    if UDP in packet:
        print(f"UDP Packet: {packet[UDP].src}:{packet[UDP].sport} -> {packet[IP].dst}:{packet[UDP].dport}")

Instead of {packet[UDP].src} one probably wants to write {packet[IP].src}.

Upvotes: 1

Related Questions