Skip to content

Instantly share code, notes, and snippets.

@JhonatanHern
Last active January 9, 2019 20:32
Show Gist options
  • Save JhonatanHern/fb17865da0da88213ffea33ea54ba304 to your computer and use it in GitHub Desktop.
Save JhonatanHern/fb17865da0da88213ffea33ea54ba304 to your computer and use it in GitHub Desktop.
My current ISP (Movistar) has a really bad system that crashes the connection every 5 or 10 minutes, my solution is this python script that pings google and restarts the connection when the ping fails.
#!/usr/bin/python
import os
import time
def checkConnection ():
return os.system("ping -c 1 google.com") == 0
def connect():
os.system("nmcli con up 'Movistar Default'")
while(True):
time.sleep(3)
if not checkConnection() :
print "connection trouble detected, restarting..."
connect()
time.sleep(15)
else:
print "connected"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment