Get the process like "netstat -anpt" on Solaris
Two ways to get which process is Listen on the specific port on Solaris
- lsof -i:port_number
e.g. lsof -i:22
- Use scripts that combined with pfiles
e.g. get_port.sh 22
#!/bin/bash
# Get the process which listens on port
# $1 is the port we are looking for
if [ $# -lt 1 ]
then
echo “Please provide a port number parameter for this script”
echo “e.g. $0 22”
exit
fi
echo “Greping for your port, please be patient (CTRL+C breaks) … ”
for i in `ls /proc`
do
pfiles $i | grep AF_INET | grep $1 | grep -v pfiles |
if [ $? -eq 0 ]
then
echo;echo “PID is $i and Process details run on port:$1”;echo
ps -cafe | grep $i | grep -v grep |
fi
done