# 每隔5秒钟监听端口是否活跃
# 介绍
[TOC]
# 每隔5秒钟监听端口是否活跃
#!/bin/bash
. /etc/init.d/functions
IPADDR=$1
PORT=$2
if [ $# -ne 2 ]; then
echo "Usage:"
echo " $0 [IPADDR|DOMAIN] [PORT]"
echo ""
echo "Examples:"
echo " $0 localhost 80"
echo " $0 192.168.1.1 80"
exit
fi
while :
do
num=`echo -n "\n"|telnet $IPADDR $PORT |grep Connected|wc -l`
if [ $num -eq 1 ]
then
action "network is open." /bin/true
else
action "network is closed." /bin/false
sleep 5
fi
done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27