Skip to content

Instantly share code, notes, and snippets.

@t510599
Last active December 9, 2018 10:43
Show Gist options
  • Save t510599/96af7196076a2885c704e8764ef1b06c to your computer and use it in GitHub Desktop.
Save t510599/96af7196076a2885c704e8764ef1b06c to your computer and use it in GitHub Desktop.
ckap auto login script

ckap login script

This script read ckap.txt and auto login for ckap
You can setup your network manager to run this script if connected to ckap.

This script used requests, you can install from pip.

Format

If your account is ck1071234 and password is mypasword
Separate account and password with space
Save ckap.txt with content:

ck1071234 mypassword

Use

python3 -m pip install requests

python3 ckap.py
import requests as req
import re
def check_connectivity():
portal = 'http://detectportal.firefox.com/success.txt'
r = req.get(portal)
if "success" == r.text.strip():
return True
else:
return (portal, r.url)
status = check_connectivity()
if status == True:
print("Already logged in!")
else:
if status[0] != status[1]: # portal location isn't equal to response location -> redirected
location = status[1]
print(location)
f = open('ckap.txt')
account, password = f.readline().split(" ") # format: account password
f.close()
magic = re.search("fgtauth\?(\w+)", location).group(1)
domain = re.search("http://(.+)/", location).group(1)
ckap_data = {
"magic": magic,
"4Tredir": "http://detectportal.firefox.com/success.txt",
"login": "登入",
"username": account.strip(),
"password": password.strip()
}
header = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "zh-TW,zh;q=0.8,en-US;q=0.5,en;q=0.3",
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0",
"Referer": location,
"Upgrade-Insecure-Requests": "1"
}
res = req.post('http://' + domain + '/', data=ckap_data, headers=header)
res.encoding = "utf-8"
if "成功" in res.text:
print("Success! Enjoy your ckap!")
elif "錯誤" in res.text:
print("Login Error: Wrong account or password!")
else:
print("Error occured!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment