懒龙谷
  • Home
  • Categories
  • Tags
  • Archives

端口监听

windows、linux、aix 查询端口号占用情况

一、windows

方法一

提升权限后

  netstat -b

方法二

  1. 查询端口占用的进程ID

      netstat -a -n  各个端口占用
      netstat -ano   各个端口占用和进程PID
    

    示例: netstat -aon | findstr "80"

      TCP    127.0.0.1:9080         0.0.0.0:0              LISTENING       4632
    
  2. 查看端口号所对应的应用程序

    tasklist | findstr " 4632"

  3. 终止进程

    1. taskkill /pid 4632 /F 
    2. taskkill /f /t /im GROOVE.exe
    
  4. 再次查询是否成功终止

    tasklist | findstr "4632"
    

  如果成功终止此次执行命令后应返回空.,则表示成功,终止 PID 为 4632 的进程。

二、Linux

方法一:

1.查询端口号占用,根据端口查看进程信息

[root@server2 ~]# lsof -i:80

2.根据进程号查看进程对应的可执行程序

ps -f -p 进程号

方法二:

  1. 根据端口号得到其占用的进程的详细信息

      netstat -tlnp|grep 80
    
  2. 根据端口号查询,查询其占用进程ID

    netstat -tlnp|grep 80|awk '{print $7}'|awk -F '/' '{print $1}'

或是用下面的命令

   netstat -pan|grep 80

三、AIX

命令:

netstat -Aan|grep 80

例如:

获得25号端口的PCB(protocol control block),
且查看协议为tcp. (输出信息中第一列即是PCB)

netstat -Aan |grep 25
f100070000d373b0 tcp4 0 0 .25 . LISTEN
f100070000d25600 udp 0 0
. .
f100070000d25400 udp 0 0
. .
f100070000d25000 udp 0 0
. .
f100070000d25c00 udp 0 0 127.255.255.255.12
.
f100070000d2d200 udp 0 0 10.10.10.255.123
.
f100070000d25a00 udp4 0 0
.514 .
f100070000d25200 udp4 0 0 .517 .*

如果是tcp连接,那么# rmsock tcpcb
如果是udp连接,那么# rmsock inpcb

     rmsock f100070000d373b0 tcpcb

The socket 0xd37008 is being held by proccess 213096 (sendmail).

结果显示25号端口正在被sendmail进程使用,PID为213096.

this guy is lazy, nothing leave

Comments
comments powered by Disqus

  • « KSH自动补全
  • db2配置远程数据库 »

Published

May 4, 2014

Category

shell

Stay in Touch

  • Powered by Pelican. Theme: Elegant by Talha Mansoor