Skip to content

Instantly share code, notes, and snippets.

@qianlongzt
Last active October 18, 2017 12:35
Show Gist options
  • Save qianlongzt/f267443b08f942c2690f8b52617c9260 to your computer and use it in GitHub Desktop.
Save qianlongzt/f267443b08f942c2690f8b52617c9260 to your computer and use it in GitHub Desktop.
杭电 WiFI Portal登录
### curl 'http://2.2.2.2/ac_portal/login.php' --data 'opr=logout'
### curl 'http://2.2.2.2/ac_portal/login.php' --data 'opr=pwdLogin&userName={stuid}&pwd={stupwd}&rememberPwd=0'
import urllib.request
import urllib.parse
import json
import sys
url = "http://2.2.2.2/ac_portal/login.php"
def login(stuid, stupwd) :
data = urllib.parse.urlencode({"opr":"pwdLogin", "userName":stuid, "pwd":stupwd, "remeberPwd":"0"}).encode("utf-8")
req = urllib.request.Request(url=url, data=data,method='POST')
f = urllib.request.urlopen(req)
print(f.status)
print(f.reason)
rep = f.read()
rep = json.loads(rep.decode('utf-8').replace("'", '"'))
print(rep['msg'])
def logout() :
data = urllib.parse.urlencode({"opr":"logout"}).encode("utf-8")
req = urllib.request.Request(url=url, data=data,method='POST')
f = urllib.request.urlopen(req)
print(f.status)
print(f.reason)
rep = f.read()
rep = json.loads(rep.decode('utf-8').replace("'", '"'))
print(rep['msg'])
def printUsage() :
print("""
Usage: %s [op] <stuid> <stupwd>
stuid: your student id
stupwd: your passsword in cas
op: login or logout
""" % sys.argv[0])
def main ():
length = len(sys.argv)
if length == 4 and sys.argv[1] == "login":
login(sys.argv[2], sys.argv[3])
elif length == 2 and sys.argv[1] == "logout" :
logout()
else :
printUsage()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment