判断网络状态

我下载net-tools 是因为我的虚拟机的系统是CentOS7的无界面模式(命令行模式)所以需要下载,如果有的话,就不需要下载了

#!/bin/bash
yum -y install net-tools
IP=`ifconfig -a|awk '{print $2}'|sed -n '2p'`
echo "IP地址是:${IP}"
code=`curl -I -m 10 -o /dev/null -s -w %{http_code} http://www.baidu.com`
if [ $code -eq 200 ]; then
        echo "is ok"    
else
        echo "is not ok"
fi

  

posted @ 2019-12-06 20:46  陈豆豆鸭  阅读(70)  评论(0)    收藏  举报