根据端口查找占用程序(win/linux/Solaris)

本文介绍了在Windows、Linux和Solaris三种操作系统中如何查询特定端口被哪个程序占用的方法。对于Windows系统,可以通过netstat结合tasklist命令实现;Linux则使用netstat与grep组合;而Solaris需要编写shell脚本来完成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

根据端口查找占用程序

url:http://daimojingdeyu.javaeye.com/blog/542921

关键字: 端口, 程序

以最常见的三个系统为例,到处搜刮了一下,整理出来备用。

1、Windows:

以查找3019端口的占用程序为例:

写道
C:/Documents and Settings/Administrator>netstat -ano|findstr 3019
UDP 127.0.0.1:3019 *:* 2728

通过上面的命令,可以找到占用3019端口的进程ID为2728,然后再使用下面的命令

写道
C:/Documents and Settings/Administrator>tasklist|findstr 2728
Thunder.exe 2728 Console 0 29,224 K

可以看到是Thunder也就是迅雷在使用3019端口

2、Linux:

写道
$netstat -pan|grep 2809

tcp 0 0 0.0.0.0:2809 0.0.0.0:* LISTEN 9493/java

3、Solaris:


先写一个port.sh的shell脚本,编辑其内容如下:
Shell代码 复制代码
  1. #more/tmp/port.sh
  2. #!/bin/sh
  3. forpidin`ls/proc`
  4. do
  5. pf=`/usr/bin/pfiles$pid2>/dev/null`
  6. ifecho$pf|grep$1>/dev/null2>&1
  7. then
  8. echo$pid
  9. /usr/bin/pargs$pid
  10. fi
  11. done
# more /tmp/port.sh
#!/bin/sh

for pid in `ls /proc`
do
       pf=`/usr/bin/pfiles $pid 2>/dev/null`
       if echo $pf | grep $1 > /dev/null 2>&1
       then
           echo $pid
           /usr/bin/pargs $pid
       fi
done
使用chmod a+x port.sh 为port.sh增加可执行权限。
然后使用 ./port.sh 53250
得到如下结果:
写道
1225
1225: /usr/lib/thunderbird/thunderbird-bin -UILocale zh-CN
-contentLocale CN
argv[0]: /usr/lib/thunderbird/thunderbird-bin
argv[1]: -UILocale
argv[2]: zh-CN
argv[3]: -contentLocale
argv[4]: CN
4212
4212: /bin/sh /tmp/port.sh 53250
argv[0]: /bin/sh
argv[1]: /tmp/port.sh
argv[2]: 53250
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值