Asyncio create_datagram_endpoinds


On my PC I have 2 NICS where each one is working with different network.

I’d like to sniff all traffic on 2nd NIC and port 54321.

This is my code.

transport, protocol = await loop.create_datagram_endpoint(
        lambda: EchoServerProtocol(),
        local_addr=('', 54321)

What shall I use in the IP address?
When I’m using the code above, I don’t receive the message at all. When executing ‘netstat’ command, while I’m putting the 2nd NIC IP address, ,I don’t see it at all.

Please advise

Your code creates a UDP endpoint. That is not suitable for sniffing traffic. I don’t think it’s possible to do that with asyncio, as it doesn’t support raw sockets. You’d need to use the socket module instead, with a RAW socket type.

1 Like

I have tried to follow this one

Which states that there is udp server

A UDP server is not the same thing as sniffing all traffic. Are you listening for UDP traffic being sent to you, or are you trying to snoop traffic being sent to a different application? Sniffing usually requires raw sockets and root access, regardless of the port number.

Incidentally, the reason you’re not seeing it in netstat may be because you’re listening on “all IPv4” rather than on a specific IP address. So in netstat, it’ll probably only show up with the listen address rather than the one your’e searching for.

1 Like