forked from syaoranwe/RuijiePortalLoginShellScript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ruijie_shu.sh
executable file
·38 lines (30 loc) · 1.93 KB
/
ruijie_shu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
#If received parameters is less than 2, print usage
if [ "${#}" -lt "2" ]; then
echo "\033[1;32mUsage: ./ruijie_template.sh <username> <password>\033[0m"
echo " Example: ./ruijie_template.sh 22122739 Passw0rd"
exit 1
fi
#Exit the script when is already online, use www.google.cn/generate_204 to check the online status
captiveReturnCode=`curl -s -I -m 10 -o /dev/null -s -w %{http_code} http://www.google.cn/generate_204`
if [ "${captiveReturnCode}" = "204" ]; then
echo "You are already online!"
exit 0
fi
#If not online, begin Ruijie Auth
#Get Ruijie login page URL
loginPageURL=`curl -s "http://www.google.cn/generate_204" | awk -F \' '{print $2}'`
#Structure loginURL
loginURL=`echo ${loginPageURL} | awk -F \? '{print $1}'`
loginURL="${loginURL/index.jsp/InterFace.do?method=login}"
# 脚本默认的服务设置是校园网,即'service="shu"' | 中国电信 | 中国联通 | 中国移动
# services=[{"aceNotShow":"false","domainName":"false","operatorDefault":"","serviceDefault":"true","serviceName":"shu","serviceShowName":"校园网"}
service="shu"
queryString="这里填写你的queryString"
queryString="${queryString//&/%2526}"
queryString="${queryString//=/%253D}"
#Send Ruijie eportal auth request and output result
if [ -n "${loginURL}" ]; then
authResult=`curl -s -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36" -e "${loginPageURL}" -b "EPORTAL_COOKIE_USERNAME=; EPORTAL_COOKIE_PASSWORD=; EPORTAL_COOKIE_SERVER=; EPORTAL_COOKIE_SERVER_NAME=; EPORTAL_AUTO_LAND=; EPORTAL_USER_GROUP=; EPORTAL_COOKIE_OPERATORPWD=;" -d "userId=${1}&password=${2}&service=${service}&queryString=${queryString}&operatorPwd=&operatorUserId=&validcode=&passwordEncrypt=false" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8" -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" "${loginURL}"`
echo $authResult
fi