2009-10-28
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, gpodder, mplayer, 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
#!/usr/bin/env python import subprocess '''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_queryshell=True) #a result of 0 is good, a result of 1 means no network if ping_result != 0:     #try to bring up the network     subprocess.call(netup_command,shell=True)     subprocess.call("beep",shell=True)

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.
Comments
2009-10-29 Anonymous:
Nasty work around...
2009-10-29 jezra:
If you have a better solution, please feel free to share.
Name:
not required
Email:
not required (will not be displayed)
Website:
not required (will link your name to your site)
Comment:
required
Please do not post HTML code or bbcode unless you want it to show up as code in your post. (or if you are a blog spammer, in which case, you probably aren't reading this anyway).
Prove you are human by solving a math problem! I'm sorry, but due to an increase of blog spam, I've had to implement a CAPTCHA.
Problem:
3 plus 4
Answer:
required
  • Tags:
  • Python
subscribe
 
2019
2016
2015
2014
2013
2012
2011
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008