-   Slackware (
-   -   Find open ports (

waddles 11-05-2012 05:45 PM

Find open ports
Found a script to search for port status open/in-use.
But am unsure of what is happening with the execute command.

exec 3>/dev/tcp/${MACHINE}/${PORT}
if [ $? -eq 0 ]
    echo "Port accepting connections"
    echo " connections not possible"

Does the use of the number 3 have a special meaning?
exec executes files so what is it doing with the 3?
How is that related to /dev/tcp ? Does /dev/tcp require the machine and port ??
Is the dotted quad the local or remote machine address?

ljb643 11-05-2012 06:55 PM

If you want to check for open ports, I recommend using 'nmap' which is included in Slackware.

If you want to know how the script works, it probably doesn't on Linux (/dev/tcp doesn't exist?). The exec 3>... tells the shell to open a new stream on file descriptor 3 to the named file or device, and continue through the script with the stream open. This use of 'exec' does not execute anything.

zux 11-06-2012 08:30 AM

yes, use nmap
simple usage

nmap localhost
nmap -p0-1000 x.x.x.x


markush 11-06-2012 08:57 AM


nmap -sV x.x.x.x
where x.x.x.x is your ip adress or hostname.


gnashley 11-06-2012 11:29 AM

The example given by the OP uses simple bash commands to check a certain port. It can also be extended to check all possible ports.

All times are GMT -5. The time now is 12:49 PM.