Hi all, In Bash /dev/tcp/host/port can be used to write to a TCP socket. This works nicely so I was very curious whether it would work the other way too: is it possible to have a Bash script listen on a particular port as if it were a server? I couldn't find anything in the Bash manual about it. Google does find a few examples but they all use nc. But that's cheating! ;-) Is it possible with just Bash, no extra tools? (If yes, please enlighten me as to how, obviously I could not get it to work.)
On a related note, I read some comments about Debian having /dev/tcp disabled in Bash because of security concerns. Would someone knowledgeable about security be able to comment on that? It doesn't make much sense to me. I mean, any Perl, Python, Ruby, etcetera script can write to a socket. Even Debian (with every option deselected) comes installed with Perl. (Yes, I installed Debian just to find out!) :-) So why should /dev/tcp in Bash be deemed such a security risk? Cheers, Hilco P.S. For the curious: #!/bin/bash exec 3<>/dev/tcp/www.google.ca/80 echo -ne "GET / HTTP/1.1\r\n">&3 echo -ne "Host: www.google.ca\r\n">&3 echo -ne "Connection: close\r\n">&3 echo -ne "\r\n">&3 cat <&3