LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Find open ports (http://www.linuxquestions.org/questions/slackware-14/find-open-ports-4175435807/)

waddles 11-05-2012 06: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.
Code:

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

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?
Thanks

ljb643 11-05-2012 07: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 09:30 AM

yes, use nmap
simple usage
Code:

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

etc.

markush 11-06-2012 09:57 AM

Code:

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

Markus

gnashley 11-06-2012 12:29 PM

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:22 PM.