Results 1 to 3 of 3
My provider sometimes kicks me and assigns a new IP address.
I'd like to write a little script which displays a message when I fall offline. What is the most ...
- 04-06-2010 #1Just Joined!
- Join Date
- Jan 2010
- Posts
- 11
Message when network goes offline
My provider sometimes kicks me and assigns a new IP address.
I'd like to write a little script which displays a message when I fall offline. What is the most reliable way to check whether I'm offline with a (bash?) script?
- 04-06-2010 #2Just Joined!
- Join Date
- Feb 2009
- Posts
- 54
If online means "connected to the network", ping your default gateway. If it means connected to the Internet, ping an internet server. If it is successful, you are "online".
- 04-07-2010 #3
#!/bin/bash
if ! ping -c 1 -w 2 4.2.2.2 &>/dev/null ; then
echo "The internet appears to be down"
else
echo "The internet appears to be up"
fi
Save as ping.sh, chmod 775 and you are good to go.


Reply With Quote