From bc61b1b452468a7c5dc1e18b985a836c5a58b4da Mon Sep 17 00:00:00 2001 From: leafee98 Date: Mon, 3 Oct 2022 13:19:38 +0800 Subject: [PATCH] add (maybe) workable code --- bwifi.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 bwifi.sh diff --git a/bwifi.sh b/bwifi.sh new file mode 100755 index 0000000..aaa3ba8 --- /dev/null +++ b/bwifi.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +username=1970111222 +password=123123321 + +# get authorizing location from 302 response header +# use an IP address to bypass the DNS lookup +echo 'sending a http request...' +res_headers=$(curl --request GET --head --no-progress-meter http://119.29.29.29/) +echo 'response received' + +if ! grep "Server: DrcomServer" <<< $res_headers ; then + echo "didn't receive a response from DrcomServer, you may be online now." + exit 1 +fi + +auth_host=$(sed -n -E 's/Location: (.*)/\1/p' <<< $res_headers | tr -d '[:space:]') +auth_host="${auth_host}/a70.htm" + +echo auth host: $auth_host +# known auth host: 10.1.206.13 +# - 10.1.206.13 +# - 192.168.211.3 + +# for wireless, which will be redirected to this location, a "@bistu" is required, +if [ "$auth_host" == *"10.1.206.13"* ] ; then + username="${username}@bistu" +fi + +# form data +title=$(curl --no-progress-meter --include \ + --data-urlencode "DDDDD=$username" \ + --data-urlencode "upass=$password" \ + --data-urlencode "R1=0" \ + --data-urlencode "R2=" \ + --data-urlencode "R3=0" \ + --data-urlencode "R6=0" \ + --data-urlencode "para=00" \ + --data-urlencode "0MKKey=123456" \ + --data-urlencode "buttonClicked=" \ + --data-urlencode "redirect_url=" \ + --data-urlencode "err_flag=" \ + --data-urlencode "username=" \ + --data-urlencode "password=" \ + --data-urlencode "user=" \ + --data-urlencode "cmd=" \ + --data-urlencode "Login=" \ + $auth_host | iconv --from-code=gb2312 --to-code=utf-8 | sed -n -E 's#(.*)#\1#p') + +echo auth result page title: $title +if [ "$title" == "认证成功页" ] ; then + echo "auth result: success" +else + echo "auth result: failed" +fi +