Skip to content

Instantly share code, notes, and snippets.

@JustinTW
Last active April 22, 2024 02:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save JustinTW/8a04eebe621afcf8098f to your computer and use it in GitHub Desktop.
Save JustinTW/8a04eebe621afcf8098f to your computer and use it in GitHub Desktop.
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
Copy link

jikker commented Nov 21, 2016

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

@jikker
Copy link

jikker commented Jul 18, 2017

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

@ChienTing
Copy link

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

@rossi229
Copy link

請問一下!!我對這真的不太懂,請問大大~對要用企業帳號登入!需要怎麼修改.

@biingen
Copy link

biingen commented Feb 27, 2024

Hi Jikker,
感謝您分享的Script,
日前都可以正常自動登入使用。
但是從上週開始,
中華電信的熱點就無法再用此Script自動登入。
每四小時就要人工登入一次,
不知您是否有更新過的Script檔案呢?
謝謝你。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment