shell腳本實現telnet測試服務端口

備註,使用方法:當前目錄下要存在需要測試的地址端口,例子:
cat ip.txt
141.12.65.17 7500

#!/bin/bash
cur_dir=$(pwd)
ipfile=$cur_dir/ip.txt
logfile=$cur_dir/log.txt
date=date
echo "****${date}" >> $logfile
if [ ! -f "$ipfile" ]; then
echo "系統檢查到在當前路徑下不存在要測試的地址清單,請補充ip.txt要測試的地址清單 EXIT"
exit
fi
if [ ! -f "$logfile" ]; then
touch $cur_dir/log.txt
fi
cat $ipfile | while read line
do
result=echo -e "\n" | telnet $line 2> /dev/null | grep Connected | wc -l
if [ $result -eq 1 ]; then
echo " $line network is nomral" >> $logfile
else
echo " $line network is warried" >> $logfile
fi
done

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章