How to check internet access using bash script in linux?

前端 未结 10 1182
孤街浪徒
孤街浪徒 2021-02-01 06:43

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 use

10条回答
  •  孤城傲影
    2021-02-01 07:22

    Using wget:

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

提交回复
热议问题