Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to tell if a port is available and open

Status
Not open for further replies.

csunix

Programmer
Mar 23, 2004
129
GB
I've been asked if two ports are available and open.
The port numbers are 5210 & 2025. If they are available and not open how do I open them? Any information would be appreciated. CS

ps Server is running Solaris 8.
 
Are the ports listening and/or established?
netstat -anf inet | grep 5210
netstat -anf inet | grep 2025

Have they been assinged?
grep 5210 /etc/services
grep 2015 /etc/services

How do you open the ports?
What application is using the ports? Is the application running?
 
Thanks for the info.
netstat -anf inet | grep 5210
netstat -anf inet | grep 2025

The first command return nothing. The second commad retuns quite a lot of information (see below).

112.1.50.1.59269 112.1.50.1.2025 32768 0 32768 0 TIME_WAIT
112.1.50.1.59271 112.1.50.1.2025 32768 0 32768 0 ESTABLISHED
112.1.50.1.2025 112.1.50.1.59271 32768 0 32768 0 ESTABLISHED
112.1.50.1.59273 112.1.50.1.2025 32768 0 32768 0 ESTABLISHED
112.1.50.1.2025 112.1.50.1.59273 32768 0 32768 0 ESTABLISHED


grep 5210 /etc/services
grep 2015 /etc/services

These commands both return nothing!!!

What is this telling me????

A libraries system using a sybase database is using the ports I believe!!!
Thanks
 
The first column is the local address and the second column is the remote address in a netstat output.

Port 2025 is established so some application is using the port, but port 5210 is not in use.

You can use 'lsof' to find what application is using a port if you don't happen to know. Or you can use this script:
Code:
#!/bin/ksh

line='-------------------------------------------------------------------------'
pids=$(/usr/bin/ps -ef | sed 1d | awk '{print $2}')


# Prompt users or use 1st cmdline argument
if [ $# -eq 0 ]; then
        read ans?"Enter port you like to know pid for:  "
else
        ans=$1
fi


# Check all pids for this port, then list that process
for f in $pids
do
        /usr/proc/bin/pfiles $f 2>/dev/null | /usr/xpg4/bin/grep -q "port: $ans"
        if [ $? -eq 0 ] ; then
                echo $line
                echo "Port: $ans is being used by PID:\c"
                /usr/bin/ps -ef -o pid -o args | egrep -v "grep|pfiles" | grep $f
        fi
done
exit 0
The script will return output like the following:
Enter port you like to know pid for: 123
-------------------------------------------------------------------------
Port: 123 is being used by PID: 256 /usr/lib/inet/xntpd

/etc/services returning nothing is fine.

So port 5210 isn't in use and 2025 is in use. You can tell them that. And you can use the script or lsof to find what process is using port 2025 to see if that is the correct application.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top