Find Process By Tcp Ip Port
  • List up all connections and ports listening status

netstat -a

  • List up all listening status

netstat -l

  • List up all ports and process status

netstat -anp

  • List up all ports listening status

netstat -lntp

  • Note

not all of the processes can be list. some of them will be list as "-" for long executing. the port information is preferred for me.

Example:
Active Internet Connections:

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp    0     0     192.168.0.1:56000   0.0.0.0:*  LISTEN  150/sshd
tcp    0     0     0.0.0.0:80        0.0.0.0:*  LISTEN  -

Reference:

http://bbs.chinaunix.net/thread-1926907-1-1.html

执行 netstart -lntp ,带了-p 参数理应显示出PID/进程名,但却变成了 “-”。这种情况我也遇到过多次。有一点规律就是:那个PID变成“-”的进程通常已跑了很久(半年、一年)了。关闭、再打开时就会这样。为此,我将HA脚本中监测oracle侦听的语句都做了修改。将原来的
netstat -lntp 2>/dev/null | grep tnslsnr | grep 1521 | wc -l
改为:
netstat -lntp 2>/dev/null | grep 1521 | wc -l
由于这只是netstat 显示问题。实际端口和进程都是正常的。所以后来也就再没有去深究。