On Linux, I can simply:
netstat -ntp | grep server_ip:port
And I get PID and process name of the program that is making given connection.
But how do I do it on Solaris?
On Linux, I can simply:
netstat -ntp | grep server_ip:port
And I get PID and process name of the program that is making given connection.
But how do I do it on Solaris?
If you're using Solaris 10 or later you could use the socketsnoop.d DTrace script. Otherwise lsof
is probably your best bet, as Dan points out.
You can try lsof
, it should work on Solaris as well (if you have it available). Try lsof -i
for network-related info.
This script will give you that information using standard Solaris commands. If you give no argument, it will list all open ports and if you give one, it will list the process having that port open:
#!/bin/ksh
pfexec pfiles /proc/* 2>/dev/null | nawk -v port=$1 '
/^[0-9]/ { cmd=$0; type="unknown"; continue }
$1 == "SOCK_STREAM" { type="tcp" }
$1 == "SOCK_DGRAM" { type="udp" }
$2 == "AF_INET" { if((port!="")&&($5!=port)) continue;
if(cmd!="") { printf("%s\n %s:%s/%s\n",cmd,$3,$5,type); cmd="" }
else { printf(" %s:%s/%s\n",cmd,$3,$5,type); }}'