在各種系統上查詢埠號被哪個程序佔用的方法
彙總了一下各種平臺下查詢埠被哪個程式佔用的方法,可以在安裝失敗,分析異常埠等時候使用。
一、Windows平臺
查詢埠1793是誰在使用,首先找到程序id.
PS C:\Users\d00101270> netstat -aon | findstr “1793”
TCP 10.70.103.84:1793 72.14.213.113:443 SYN_SENT 792
上面最後一列是程序id, 我們使用tasklist來查詢程序id對應的程序名
PS C:\Users\d00101270> tasklist | findstr “792”
GoogleUpdate.exe 792 Console 1 8,220 K
二、Linux
第一種方案:
$netstat -pan | grep 19916
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 10.71.173.225:19916 0.0.0.0:* LISTEN 28517/DiameterAdpt
第二種方案:
$lsof -i:23
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
telnet 10582 d101270 3u IPv4 263403399 TCP linux227.huawei:61172->10.71.173.225:telnet (ESTABLISHED)
三、AIX
$netstat -Aan|grep 30542
f10000f303321b58 tcp4 0 0 *.30542 *.* LISTEN
$rmsock f10000f303321b58 tcpcb
The socket 0x3321800 is being held by proccess 692476 (db2sysc).
四、HP-UX
使用lsof -i 可以查到程式名,程序號, 如果查9090埠
#lsof -i|grep 9090
java 29607 sync 30u IPv4 0x12b6ce380 0t0 TCP *:9090 (LISTEN)
java 29607 sync 35u IPv4 0x122c194c0 0t1343 TCP zy:9090->10.17.109.110:1206 (ESTABLISHED)
java 29607 sync 36u IPv4 0xca46d9c0 0t2680 TCP zy:9090->172.16.4.109:1105 (ESTABLISHED)
java 29607 sync 37u IPv4 0x126e140c0 0t2796 TCP zy:9090->172.16.4.111:1094 (ESTABLISHED)
java 29607 sync 38u IPv4 0x105c25b80 0t2409 TCP zy:9090->172.16.4.122:1576 (ESTABLISHED)
java 29607 sync 39u IPv4 0x106bc4040 0t500 TCP zy:9090->10.17.77.96:1300 (ESTABLISHED)
java 29607 sync 41u IPv4 0xca2a1dc0 0t443 TCP zy:9090->132.97.238.187:1642 (ESTABLISHED)
java 29607 sync 42u IPv4 0x12245f200 0t2443 TCP zy:9090->132.97.191.143:2928 (ESTABLISHED)
java 29607 sync 47u IPv4 0x122c19dc0 0t2347 TCP zy:9090->10.17.109.110:1207 (ESTABLISHED)
#ps -ef|grep 29607
sync 29607 1 0 May 19 ? 163:02 /opt/java1.4/bin/PA_RISC2.0/java -server -Xms128m -Xmx512m -Dja
root 17445 16305 1 17:31:19 pts/to 0:00 grep 29607
五、SUN Solaris
第一種方案:
1. 使用下面shell script,先建立一個port.sh檔案:
# 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
2. 執行port.sh, 傳入埠號,比如53250 :
# /tmp/port.sh 53250
3. 執行結果如下:
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
第二種方案:
下載lsof軟體, 使用lsof軟體可以實現,同Linux.
第三種方案:
使用MDB
from socket info (netstat output), you can know its vnode
from vnode info, you can know which process owns it
from process info, you can know its args, so comes the result.