wenlibin02 wenlibin02 - 1 year ago 105
Linux Question

How to check internet access using bash script in linux?

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 ...

That is, when I use:
ping -q -w1 -c1
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

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
may be a good alternative, but how to use?)

Answer Source

Using wget:


wget -q --tries=10 --timeout=20 --spider http://google.com
if [[ $? -eq 0 ]]; then
        echo "Online"
        echo "Offline"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download