以最常见的三个系统为例,到处搜刮了一下,整理出来备用。
1、Windows:
以查找3019端口的占用程序为例:
写道
C:\Documents and Settings\Administrator>netstat -ano|findstr 3019
UDP 127.0.0.1:3019 *:* 2728
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.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
tcp 0 0 0.0.0.0:2809 0.0.0.0:* LISTEN 9493/java
3、Solaris:
先写一个port.sh的shell脚本,编辑其内容如下:
# 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
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
查询端口占用方法
本文介绍了在Windows、Linux和Solaris三种操作系统中查询特定端口被哪个程序占用的方法。以Windows为例,通过组合使用netstat和tasklist命令,可以找出占用指定端口的进程;在Linux中,则可通过netstat命令结合grep进行搜索;而在Solaris系统中,利用自定义的shell脚本来查找。
3376

被折叠的 条评论
为什么被折叠?



