Shell检测IP和端口
检测IP
Eg.
RET_FAIL=1
RET_SUCCESS=0
# check ip is reach
# input ip / ip:port
function ip_is_reach()
{
l_host=${1}
l_host_ip=$( echo ${l_host} | cut -f1 -d ':' )
detect_log "ping host ${l_host_ip}"
ping -c2 -i0.1 -W2 ${l_host_ip} 2>&1 > /dev/zero
if [ $? != 0 ]; then
return ${RET_FAIL};
else
return ${RET_SUCCESS};
fi
}
检测IP和端口
Eg.
RET_FAIL=1
RET_SUCCESS=0
# check ip:port is reach
# input: ip:port
function ip_port_is_reach(){
l_host=${1}
l_host_ip=""
l_host_port=""
# "ip:host"解析成l_host_ip和l_host_port
if [ `echo ${l_host} | grep -c ":"` -ne '0' ]; then
l_host_ip=$(echo ${l_host} | cut -f1 -d ':' )
l_host_port=$(echo ${l_host} | cut -f2 -d ':' )
fi
result=`echo -e "\n" | telnet ${l_host_ip} ${l_host_port} 2>/dev/null | grep Connected | wc -l`
if [ $result != 1 ]; then
return ${RET_FAIL};
else
return ${RET_SUCCESS};
fi
}