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?

link|improve this question

74% accept rate
feedback

3 Answers

up vote 3 down vote accepted

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.

link|improve this answer
feedback

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

link|improve this answer
Good hint, but unfortunately, I don't have lsof there. – depesz Apr 6 '10 at 15:34
feedback

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); }}'
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.