Shortest Port Scanner Write the shortest program that will attempt to connect to open ports on a remote computer and check if they are open. (It's called a Port Scanner)

Take input from command line arguments.

your-port-scanner host_ip startPort endPort


Assume, startPort &lt; endPort (and endPort - startPort &lt; 1000)

Output: All the open ports between that range should space or comma seperated.
sh/netcat, 39

nc -vz $1 $2-$3 2&gt;&amp;1|cut -f3 -d\ |xargs


Netcat does the scanning and returns results in this form on standard error:

localhost [127.0.0.1] 22 (ssh) open
localhost [127.0.0.1] 25 (smtp) open


cut and xargs extract the port number and make a single line out of it.

Remind me to shut SMTP down on that node.