How to check internet access using bash script in linux?

前端 未结 10 1390
孤街浪徒
孤街浪徒 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:04

    Without wget

    #!/bin/bash
    
    echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null 2>&1
    
    if [ $? -eq 0 ]; then
        echo "Online"
    else
        echo "Offline"
    fi
    

    Enjoy ;)

提交回复
热议问题