Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 2 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.

share|improve this answer

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

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.