Last active
September 30, 2016 09:21
-
-
Save cllu/2f4a689f50604e8e4c3c to your computer and use it in GitHub Desktop.
CUHK Network auto connection Python script
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
#!/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