如何在Linux中使用bash脚本检查Internet访问? [英] How to check internet access using bash script in linux?

查看:74
本文介绍了如何在Linux中使用bash脚本检查Internet访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的学校中,互联网不可用(每天23:0以后,学校都会杀死互联网,让我们上床睡觉> ..<),但是ping永远不会停止,尽管我已经使用了参数ping -w1 ....

In my school, the internet is not available(every night after 23:0 the school will kill the internet, to put us in bed >..<), then the ping will never stop, though I have used the parameter ping -w1 ....

也就是说,当我使用:ping -q -w1 -c1 8.8.8.8检查互联网是否打开/关闭时,它将在那里没有任何输出并且不会退出,就像我使用单个cat一样.

That is, when I use: ping -q -w1 -c1 8.8.8.8 to check if the internet is up/down, It will be there without any output and doesn't exit, just like I am using a single cat.

你能理解我的问题吗???我不知道为什么会这样,但是我认为问题与 school-internet-service 有关.有什么建议吗? (我认为wget可能是一个很好的选择,但是如何使用?)

Can you understand my question??? I don't know why it's like this, But I think the problem is related to the school-internet-service. Any suggestion? (I think wget may be a good alternative, but how to use?)

推荐答案

使用wget:

#!/bin/bash

wget -q --tries=10 --timeout=20 --spider http://google.com
if [[ $? -eq 0 ]]; then
        echo "Online"
else
        echo "Offline"
fi

这篇关于如何在Linux中使用bash脚本检查Internet访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆