Command to know port no

Hi,

I want to know command which will display which application is running on which port.... apart from netstat,

configuration file is /etc/inet/services

for ex:
to know about telnet port u can use
# grep telnet /etc/inet/services
telnet 23/tcp.

Awadhesh

Thanks Awadhesh for your quick response, but any command is there which will display application name along with port number?

Download lsof from Freeware for Solaris

Then run lsof -i - see man lsof for more.

Cheers,
ZB

I am not aware other that netstat.

Hi,

netstat in Solaris will not show which process is using certain port, do fix that try to use pfiles, this is a cool tool in Solaris which shows you all the files openned by the process, since a connection is a file in Unix , using pfiles is easy. Look the following shell script :

-----
for a in `ps -ef | nawk '{print $2}'`
do
pfiles $a | grep 80 (your port number)
done
-----

Later you can automate an improve this script, this is just to give U a clue how to find your stuff there, hope that helps.

Regarding,

Fernando Ramos.

I actually wrote a fairly comprehensive script to do this a while back

#!/bin/bash

# use this where lsof (for lsof -i tcp:<port>) isn't available

AWK="/usr/bin/awk"
ECHO="/bin/echo"
PARGS="/usr/bin/pargs"
PFILES="/usr/bin/pfiles"
PS="/usr/bin/ps"
SED="/usr/bin/sed"

${PS} -ef | ${SED} '1d' | while read PS_LINE; do
   PS_PID=$( ${ECHO} "${PS_LINE}" | ${AWK} '{print $2}' )
   PS_PROC=$( ${PARGS} ${PS_PID} | ${SED} -n '1p' | ${SED} 's/^[0-9][0-9]*:[    ]*\(.*\)$/\1/' )
   PORT_USAGE=$( ${PFILES} ${PS_PID} | ${AWK} '/AF_INET/ { printf( "\t%s(%s)\n", $3, $5 ) }' )
   if [ "${PORT_USAGE}" != "" ]; then
      ${ECHO} "${PS_PROC} [PID: ${PS_PID}]"
      ${ECHO} "${PORT_USAGE}"
   fi
done

exit 0

Sample output...

...
        /usr/lib/inet/xntpd [PID: 366]
        0.0.0.0(123)
        127.0.0.1(123)
        192.168.xx.14(123)
        192.168.xx.15(123)
...

Cheers,
ZB