shell测试一个网站是否开通80端口

1:curl(1查看http返回状态)

webStatus=`curl -I -s http://www.baidu.cc|grep 200|wc -l`
[ $webStatus -eq 1 ] && echo "running" || echo "not running" 
//或者
httpHeader=`curl -s -I http://www.baidu.cc|sed -n '1p'|cut -d " " -f2`
[ $httpHeader == 200 ] && echo "running" ||"not running"  

2:curl(2查看命令执行是否成功)

curl -s http://www.baidu.com >&/dev/null
[ $? -eq 0 ] && echo "running" ||echo "not running" 

 3:telnet

echo -e "\n"|telnet www.baidu.com 80|grep Connected|wc -l
返回1就表示已开启

 4:nc

nc -w 5 .www.baidu.com 80 && echo "running" || "not running"

 5:最后贴一个动态设置ip和端口的例子

[root@linhexiao shellTest]# cat check_web1.6.sh 
#!/bin/bash
#create by linhexiao 
#V1.6

[ -f /etc/init.d/functions ] && . /etc/init.d/functions||exit 1
if [ $# -ne 2 ];then
	 echo "Usage:$0 ip port"
	 exit 1
fi

httpPortNum=`nmap $1 -p $2|grep open|wc -l`

if [ $httpPortNum == 1 ];then
	action "$1 $2 is running " /bin/true;
else
	action "$1 $2 not running " /bin/false;
fi

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值