Monday Jul 24, 2006

Get application pid listening on a network port in Solaris (aka netstat -npl in Solaris?)

Some time ago, I was in need of this functionality.
This little silly script, however very uneffective will check which apps listents on the given port number.
Maybe I should think about writing something more effective ... or just file a Request For Enhancement against netstat on Solaris?

Script get_port_pid.sh:

#!/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
if [ $? -eq 0 ]
then
echo Is owned by pid $i
fi
done

About

Different stories on my ramblings under the Sun/Oracle

Search

Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today