Skip to content

Instantly share code, notes, and snippets.

@lebuni
Last active May 4, 2023 13:06
Show Gist options
  • Save lebuni/08b333ea7c1cf47403c38607e98f633a to your computer and use it in GitHub Desktop.
Save lebuni/08b333ea7c1cf47403c38607e98f633a to your computer and use it in GitHub Desktop.
Automatically login to open WiFi: This script accepts automatically the terms and conditions, that often needs to be confirmed when logging in into an open WiFi.
#!/usr/bin/env python
"""Connects to wifi in case terms and conditions need to be accepted"""
import mechanize
def accept_wifi_terms():
URL = 'https://www.google.com/'
br = mechanize.Browser()
br.set_handle_redirect(True)
br.set_handle_equiv(True)
br.set_handle_robots(False)
br.open(URL)
if URL == br.geturl():
print("internet already working")
return True
try:
br.select_form(nr=0)
except mechanize.FormNotFoundError:
print("No form found")
return False
br.submit()
print("Terms accepted")
return True
if __name__ == "__main__":
accept_wifi_terms()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment