0

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?

3 Answers 3

2

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.

0

You can try lsof, it should work on Solaris as well (if you have it available). Try lsof -i for network-related info.

1
  • Good hint, but unfortunately, I don't have lsof there.
    – user13185
    Apr 6, 2010 at 15:34
0

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); }}'

You must log in to answer this question.