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?
source
share