Skip to content

Instantly share code, notes, and snippets.

@cdw
Created October 27, 2015 03:51
Show Gist options
  • Save cdw/26f7a11b040372a0545b to your computer and use it in GitHub Desktop.
Save cdw/26f7a11b040372a0545b to your computer and use it in GitHub Desktop.
modem_check_reset.py - check our internet connection and reset the modem if it doesn't seem to be up.
#!/usr/bin/env python
# encoding: utf-8
"""
modem_check_reset.py - check our internet connection and reset the modem if it
doesn't seem to be up. This is for a Motorola SB5101. This is intended to be run
from a cron script every 20 min or so, thus the following would be added to the
cron jobs:
0 * * * * /path/to/modem_check_reset.py
20 * * * * /path/to/modem_check_reset.py
40 * * * * /path/to/modem_check_reset.py
Created by Dave Williams on 2015-10-26, public domain
"""
import os
def ping(host):
"""Ping a host and report if connected"""
connected = os.system("ping -c 1 " + host)==0
print "Ping to %s returned %s"%(host, str(connected))
return connected
if __name__=='__main__':
if ping('yahoo.com'):
pass
elif ping('google.com'):
pass
elif ping('washington.edu'):
pass
else:
print "No connections found, restarting modem"
os.system('curl -d ResetReq=1 http://192.168.100.1/goform/RgConfig')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment