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 Answers3

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.

Gerald Combs
  • 6,441
  • 25
  • 35
0

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

Dan Andreatta
  • 5,454
  • 2
  • 24
  • 14
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); }}'
jlliagre
  • 8,861
  • 18
  • 36