查詢服務器端口腳本
阿新 • • 發佈:2018-12-29
urn rst div tcp echo value check first tst
#!/bin/bash #IPaddr=`ifconfig | grep inet\\\\s | grep -v "127.0.0." | sed "s/addr://g"| awk ‘{print $2}‘` check_port() { linenum=$(netstat -tlpn | grep "\b$1\b" | wc -l); echo "$linenum" } function getfreeport() { first=$1 last=$2 for (( port = $first; port <= ${last}; port++ ))do #(echo > /dev/tcp/$IPaddr/$port) &> /dev/null echo $port check_values=$(check_port $port); echo "check=$check_values"; if [ $check_values -eq 0 ];then echo "端口$port可以使用" break return $port fidone } port=$(getfreeport 20880 20900) echo "free port=${port}"
查詢服務器端口腳本