Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auto login cht-wifi for dd-wrt
#!/bin/sh
# description: check cht-wifi login status, and auto login if no login.
# default script path: /mnt/sda1/mnt/scripts/login-cht-wifi.sh
# author: JustinTWD <justintwd@gmail.com>
# date: 2016/03/12
USERNAME=YOUR_CHT_ACCOUNT
PASSWD=YOUR_CHT_PASSWORD
LOGFILE=/mnt/sda1/log/cht-wifi.log
TMPSESSION=/tmp/cht_session.tmp
login_v1(){
/opt/bin/curl -d cht_user=$USERNAME -d passwd=$PASSWD -d username=$USERNAME%40hinet.net -d password=$PASSWD -d custom=cht -d session=$(/opt/bin/curl -I www.google.com.tw | grep Location | cut -d "&" -f 1 | cut -d "=" -f 2) https://wlanac.hinet.net/loginpages/userlogin.shtml
}
login_v2(){
rm -f $TMPSESSION
R1=$(/opt/bin/curl -c $TMPSESSION -k \
$(/opt/bin/curl -Ls -o /dev/null -w %{url_effective} http://google.com) 2>&1 \
| grep redirect_url= \
| awk -F"'" '{print $2}')
R2=$(/opt/bin/curl -b $TMPSESSION -c $TMPSESSION -k -i $R1 2>&1 \
| grep Location \
| awk '{print $2}')
/opt/bin/curl -b $TMPSESSION -c $TMPSESSION -k \
-H "Referer: $R2" \
-d cht_user=$USERNAME -d passwd=$PASSWD -d username=$USERNAME%40hinet.net -d password=$PASSWD -d custom=cht \
https://wlangw.hinet.net/v2_0/cht_auth/auth_page.php
}
main(){
testing=$(/opt/bin/curl -I www.google.com.tw | grep "200 OK")
echo "============================================="
if [ "$testing" != "" ]; then
echo "wifi logined."
elif [ "$1" == "" ]; then
echo "`date` You need login CHT Wi-Fi PWLAN." | tee $LOGFILE
login_v2;
fi
}
main;
@jikker

This comment has been minimized.

Copy link

commented Nov 21, 2016

hi...
我想請問一下 你是用哪台機器執行這個sh檔呢?
機器是不是一定要有USB port?

@jikker

This comment has been minimized.

Copy link

commented Jul 18, 2017

自問自答一下 XD
一定要有usb 自帶rom的怕太小
我寫的完整教學
http://www.jikker.net/2017/07/dd-wrt-cht-wi-fi.html

@ChienTing

This comment has been minimized.

Copy link

commented Apr 2, 2018

請問 現在還可以用嗎?
Hinet 驗證網址是否有改 我一直無法自動登入
跪求指點 謝謝....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.