`How to check through Bash there is Internet or not?
K
K
kkoshakk2018-02-07 22:29:14
bash
kkoshakk, 2018-02-07 22:29:14

How to check through Bash there is Internet or not?

My version is:
#Check Internet Connection
echo -n "Checking Internet Connection..."
ERR=`ping 8.8.8.8 -c 5 2>&1 > /dev/null` && echo "[ OK ]" || { echo "ERROR" && exit; }
Maybe there is a more elegant and better solution?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
X
xotkot, 2018-02-10
@kkoshakk

fping 8.8.8.8
so for example you can very quickly find out which hosts are pinged on the local network (192.168.1.1/24)

L
lojcin, 2018-02-07
@lojcin

Basics of BASH. Part 1

P
pfg21, 2018-02-08
@pfg21

the result of the previous command is stored in the environment variable $?
those. after
ping -c 1 8.8.8.8
the value of $? will be equal to 0
and after pinging a non-existent address (imitation of a broken tyrnet)
ping -c 1 192.168.250.250
value $? will be equal to 1
value of $? save to another variable or substitute in if
because it will be "quickly overwritten" by the result of subsequent commands.

C
CityCat4, 2018-02-08
@CityCat4

First you need to decide what is "there is the Internet." Is there a connection to the provider's gateway? With a city level traffic exchange point? With a google server? With a cat server, pipe, steam, tanks? The presence of a connection with one does not at all mean the presence of a connection with others :) (with the exception of the provider's router - the absence of a connection with it is the absence of the Internet at all).

K
kkoshakk, 2018-02-10
@kkoshakk

Is it possible to use NetworkManager to check if there is no Internet connection?
Just a ping, by and large, it's just checking the availability of a certain host...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question