I'm looking for a standard way to test the existance of an internet connection under Linux. Is anyone aware of any standard methods?
I'm looking for a standard way to test the existance of an internet connection under Linux. Is anyone aware of any standard methods?
You could always ping a website like google.
We must be the change we wish to see - Gandhi
Usually, I just ping a site. Actually, I use google because it is always there.
Yea, I guess that's an option. I was wondering because I want to pop up a dialog if an internet connection isn't detected.
Better solution in Bash (the old program was for Windows)
You can tweak this to your liking. It pings google, and if it fails, it will give a popup notifying you, if it suceeds, it waits 30 seconds and does it again.Code:#! /bin/bash main() { ping -c 64.233.169.103 > /dev/null if [ "$?" -eq 0 ] then zenity --info --text "Internet Lost"; else sleep 30 main fi } main
Last edited by LaRoza; March 22nd, 2008 at 05:16 AM.
actually the line ping -c 64.233.169.103
gives you the usage because you need to specify the limit of pings to the -c flag ie:
ping -c 1 64.233.169.103
so in total it should look like:
Code:#! /bin/bash main() { if ping -c 1 64.233.169.103 > /dev/null;then zenity --info --text "Internet Lost"; else sleep 30 main fi } main
Last edited by alex_o; December 31st, 2009 at 02:31 PM. Reason: forgot code tags DOH!
@alex_o actually your code above does alert the user when the connection is working! The instructions in the if and else statements should be switched.
Fabio Varesano
hi
you have to use: netstat -punt | grep -i VERBUNDEN ( in english i think it is CONNECTED ) in a selfmade script.
and then, if $? is zero --> do your stuff ( 0 == VERBUNDEN || CONNECTED - depends on your language)
--> -punt will give you the name and the process-id of the process.
ciao
Last edited by rnerwein; June 14th, 2010 at 07:47 PM.
"What is the robbing of a bank compared to the FOUNDING of a bank?" Berthold Brecht
Uuuh, I don't think that this is a good idea. First of all, even if there is a connection, if there is no process at the point of time of checking this, you will receive a false negative. Then, intranet connections are also taken into account. Finally, there are pay-per-use internet connection providers which simply reroute all port-80 traffic through the connection to their payment site and block all other connections until you have bought some connectivity. Here, you get a false positive with your approach.
Finally, for getting rid of the language problem, you can always set "LANG=C" before calling the tool to make sure that the result is in english: "LANG=C netstat -punt"
Bookmarks