#!/bin/bash
#测试端口
ip="121.12.*.*"
function test_port()
{
min_port=$1
max_port=$2
while [ $min_port -le $max_port ]
do
nc -v -z -w 3 $ip $min_port > /dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "$min_port:ok \c"
else
echo $min_port:"fail"
fi
min_port=`expr $min_port + 1`
done
echo "------------------"
}
test_port 8101 8111
test_port 8201 8206
test_port 8301 8306
test_port 8401 8404
test_port 8901 8910
test_port 8921 8922
test_port 8931 8932
test_port 8941 8944
test_port 8601 8603
test_port 8701 8704
test_port 8801 8803
test_port 9771 9772
test_port 9661 9664
[root@localhost ~]# ./test_port.sh
8101:ok8102:ok8103:ok8104:ok8105:ok8106:ok8107:ok8108:ok8109:ok8110:ok8111:ok------------------
8201:ok8202:ok8203:ok8204:ok8205:ok8206:ok------------------
8301:ok8302:ok8303:ok8304:ok8305:ok8306:ok------------------
8401:ok8402:ok8403:ok8404:ok------------------
8901:ok8902:ok8903:ok8904:ok8905:ok8906:ok8907:ok8908:ok8909:ok8910:ok------------------
8921:ok8922:ok------------------
8931:ok8932:ok------------------
8941:ok8942:ok8943:ok8944:ok------------------
8601:ok8602:ok8603:ok------------------
8701:ok8702:ok8703:fail
8704:ok------------------
8801:ok8802:ok8803:ok------------------
9771:ok9772:ok------------------
9661:ok9662:ok9663:ok9664:ok------------------