No one likes a quitter; especially when that one is me, and the quitter is the network connection of my media playing computer.
The media computer is connected to both my television and stereo, and runs MPD
, and sap
. For the most part access to the machine is via SSH.
Every now and then, for reasons I have yet to determine, the wireless network connection of my media player drops, and it is damn frustrating when I can't ssh to my media player.
If only there was a way to test the machines network connection and restart the connection if the network is down....
Time for some Python
'''declare some variables'''
test_ip = "192.168.1.1"
ping_query = "ping -c 1 %s >/dev/null" % ( test_ip )
netup_command = "netcfg -r HomeNetworkConfig"
#try to ping the test ip address
ping_result = subprocess.call(ping_query, shell=True)
#a result of 0 is good, a result of 1 means no network
if ping_result != 0:
#try to bring up the network
This python script runs every 2 minutes and pings my router. If the network is up, the result of the ping command will return 0. If something other than zero is returned, a command is run that will bring up the network connect.
Now stop reading, and go do whatever is that you do.