Skip to content

Instantly share code, notes, and snippets.

@lukestanley
Last active October 30, 2017 12:48
Show Gist options
  • Save lukestanley/99d617fd2545dc48d9565ade7c6b8641 to your computer and use it in GitHub Desktop.
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.
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