Last active
October 30, 2017 12:48
-
-
Save lukestanley/99d617fd2545dc48d9565ade7c6b8641 to your computer and use it in GitHub Desktop.
A simple script I use for reconnecting my wifi device on a network that has a portal. Used on Ubuntu 16.04.3 LTS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import system as run | |
from random import random | |
import requests | |
from time import sleep | |
def reconnect_wifi(): | |
run("nmcli d connect wlp3s0") | |
run("firefox http://bbc.co.uk/?"+str(random())) | |
def are_we_connected(): | |
try: | |
r = requests.get('http://bbc.co.uk') | |
assert('News' in r.text) | |
return True | |
except: | |
print('Not connected') | |
return False | |
while True: | |
if are_we_connected() is False: | |
reconnect_wifi() | |
sleep(30) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment