2011-05-11 96 views

回答

0

如果你沒有安裝lsof的你,這裏是一個使用標準Solaris單向命令:

pfiles /proc/* 2>/dev/null | nawk -v port=$port ' 
/^[0-9]/ { cmd=$0; type="unknown"; continue } 
$1 == "SOCK_STREAM" { type="tcp" } 
$1 == "SOCK_DGRAM" { type="udp" } 
$2 == "AF_INET" { if((port!="")&&($5!=port)) continue; 
        if(cmd!="") { printf("%s\n %s:%s/%s\n",cmd,$3,$5,type); cmd="" } 
        else { printf(" %s:%s/%s\n",cmd,$3,$5,type); }}' 

將端口設置變量,你正在尋找的端口號,如果有的話,或設置就可以到查看正在使用的所有IPV4端口。

1

我從某處得到了他的劇本。登錄solaris系統。打開vi編輯器。進入插入模式。複製並粘貼此腳本。關閉文件。給予執行權限。使用-p或-P swithc運行此腳本。它將給出一個帶有PID,PROCESS名稱和端口的輸出。

PCP是一種腳本,使管理員能夠查看Solaris系統上正在使用的打開的TCP端口。它將端口映射到PID,反之亦然。它接受通配符,並且還會一目瞭然地顯示所有開放端口及其相應的PID。這是很好的腳本給出了一個非常好的輸出。去嘗試一下。

實施例: #pcp -p PORT_NUMBER or #pcp -P PROCESS_ID

#!/usr/bin/ksh 
# 
# Wildcards are accepted for -p and -P options. 
# 
# for the help, much appreciated. 
i=0 
while getopts :p:P:a opt ; do 
    case "${opt}" in 
    p) port="${OPTARG}";i=3;; 
    P) pid="${OPTARG}";i=3;; 
    a) all=all;i=2;; 
    esac 
done 
if [ $OPTIND != $i ]; then 
    echo >&2 "usage: $0 [-p PORT] [-P PID] [-a] (Wildcards OK) " 
    exit 1 
fi 
shift `expr $OPTIND - 1` 
if [ "$port" ]; then 
    # Enter the port number, get the PID 
    # 
    port=${OPTARG} 
    echo "PID\tProcess Name and Port" 
    echo "_________________________________________________________" 
    for proc in `ptree -a | awk '/ptree/ {next} {print $1};'` ; do 
     result=`pfiles $proc 2> /dev/null| egrep "port: $port$"` 
     if [ ! -z "$result" ];then 
     program=`ps -fo comm= -p $proc` 
     echo "$proc\t$program\t$port\n$result" 
     echo "_________________________________________________________" 
     fi 
    done 
elif [ "$pid" ]; then 
    # Enter the PID, get the port 
    # 
    pid=$OPTARG 
    # Print out the information 
    echo "PID\tProcess Name and Port" 
    echo "_________________________________________________________" 
    for proc in `ptree -a | awk '/ptree/ {next} $1 ~ /^'"$pid"'$/ {print $1};'`; do 
     result=`pfiles $proc 2> /dev/null| egrep port:` 
     if [ ! -z "$result" ];then 
     program=`ps -fo comm= -p $proc` 
     echo "$proc\t$program\n$result" 
     echo "_________________________________________________________" 
     fi 
    done 
elif [ $all ]; then 
    # Show all PIDs, Ports and Peers 
    # 
    echo "PID\tProcess Name and Port" 
    echo "_________________________________________________________" 
    for proc in `ptree -a | sort -n | awk '/ptree/ {next} {print $1};'` ; do 
     out=`pfiles $proc 2>/dev/null| egrep "port:"` 
     if [ ! -z "$out" ];then 
     name=`ps -fo comm= -p $proc` 
     echo "$proc\t$name\n$out" 
     echo "_________________________________________________________" 
     fi 
    done 
fi 
exit 0 
+0

尼斯腳本。需要對我的5.10系統上的「-P」選項稍作調整,但其他方面相當不錯。 *那裏的幫助,非常感謝*評論來自? – Signal15 2014-12-03 18:19:17