Skip to content

Instantly share code, notes, and snippets.

@cllu
Last active September 30, 2016 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cllu/2f4a689f50604e8e4c3c to your computer and use it in GitHub Desktop.
Save cllu/2f4a689f50604e8e4c3c to your computer and use it in GitHub Desktop.
CUHK Network auto connection Python script
#!/usr/local/bin/python3
import requests
USER = "USER"
PASSWORD = "PASSWORD"
def login():
"""Post the login info to the CUHK authentication server"""
url = "https://securelogin.net.cuhk.edu.hk/cgi-bin/login"
data = {
'user': USER,
'password': PASSWORD,
'cmd': 'authenticate',
'Login': 1
}
resp = requests.post(url, data=data, verify=False)
print(resp.url, resp.content)
def connected():
"""Check if we have Internet connection"""
try:
resp = requests.get('http://www.google.com.hk', verify=False)
return "securelogin.net.cuhk.edu.hk" not in resp.url
except Exception as err:
pass
return False
if __name__ == "__main__":
if not connected():
login()
print("Connection status:", connected())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment