How to test an Internet connection with bash?

后端 未结 19 1421
青春惊慌失措
青春惊慌失措 2020-11-27 09:26

How can an internet connection be tested without pinging some website? I mean, what if there is a connection but the site is down? Is there a check for a connection with the

19条回答
  •  北海茫月
    2020-11-27 10:11

    shortest way: fping 4.2.2.1 => "4.2.2.1 is alive"

    i prefer this as it's faster and less verbose output than ping, downside is you will have to install it.

    you can use any public dns rather than a specific website.

    fping -q google.com && echo "do something because you're connected!"

    -q returns an exit code, so i'm just showing an example of running something you're online.

    to install on mac: brew install fping; on ubuntu: sudo apt-get install fping

提交回复
热议问题