Listen for UDP packet returns in bash

I played with bash network support (4.0.33) for training and tried to create a port scanner in bash. For TCP, I opened a TCP / IP socket with

exec 3<>/dev/tcp/192.0.2.1/80

and appropriate action was taken if the connection was refused or the system call timeout. However, with UDP, I can easily send a packet with

echo > /dev/udp/192.0.2.1/53

but how to read returned packets from the correct socket? I mean that the UDP datagram sent to 192.0.2.1 has a source port from the ephemeral range of ports, and therefore I donโ€™t know which socket in the directory /dev/udp/192.0.2.1/should be read. Or is this impossible without external utilities like tcpdump?

+4
source share
1 answer

Bash UDP ( Debian/Ubuntu ). netcat:

nc -u 192.0.2.1 53

. coproc netcat. netcat.

Bash . , Python, UDP, , .

+4

Source: https://habr.com/ru/post/1544778/


All Articles