Skip to content

Instantly share code, notes, and snippets.

@cdlewis
Last active December 17, 2015 01:49
Show Gist options
  • Save cdlewis/5530638 to your computer and use it in GitHub Desktop.
Save cdlewis/5530638 to your computer and use it in GitHub Desktop.
Sometimes the only way to connect to Uniwireless is to keep trying!
#!/usr/bin/python
from subprocess import check_output, call
attempts = 0
# Keep connecting to Uniwireless until you get a valid IP.
while True:
try:
ip = check_output( [ "ipconfig", "getifaddr", "en1" ] )
except subprocess.CalledProcessError:
continue
if ip.startswith( "172" ):
print "Connected!"
break
else:
print "Attempt", attempts
attempts += 1
call( [ "ifconfig", "en1", "down" ] )
call( [ "ifconfig", "en1", "up" ] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment