Answer the question
In order to leave comments, you need to log in
`
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
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)
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.
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).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question