Created
November 27, 2013 12:15
-
-
Save v6ak/7674735 to your computer and use it in GitHub Desktop.
Přihlašovací skript pro wlan_fi na FI MU. Pro klasický Linux i Android.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http_user=... | |
| http_password=... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| #lynx https://fadmin.fi.muni.cz/auth/sit/wireless/login.mpl | |
| #LOGIN_URL=https://fadmin.fi.muni.cz/auth/sit/wireless/login.mpl # old IPv4 only | |
| LOGIN_URL=https://fadmin.fi.muni.cz/auth/sit/wireless/login2.mpl # new IPv4+IPv6 | |
| #export WGETRC=/home/browser/fadmin-wgetrc | |
| export WGETRC=~/auth/fadminrc | |
| export RUN_DHCLIENT=0 # useful on Android phones with Debian chroot | |
| export FADMIN_INTERFACE="*" # it is useful to force wlan0 on Android devices; it is useful to leave it "*" on notebooks | |
| function dhc { | |
| if [ "$RUN_DHCLIENT" == 1 ]; then | |
| sudo /sbin/dhclient | |
| fi | |
| } | |
| function fdate { | |
| date +%Y-%m-%d--%H-%M-%S | |
| } | |
| function getMyIp { | |
| if [ "$FADMIN_INTERFACE" == "*" ]; then | |
| echo '*' | |
| else | |
| /sbin/ifconfig "$FADMIN_INTERFACE" | /bin/grep -oE 'inet addr:([0-9]{1,3}\.){3}[0-9]{1,3}' | /bin/sed 's/^inet addr://' | |
| fi | |
| } | |
| function getMyIp6 { | |
| if [ "$FADMIN_INTERFACE" == "*" ]; then | |
| echo '*' | |
| else | |
| /sbin/ifconfig "$FADMIN_INTERFACE" | /bin/grep -oE 'inet6 addr: ([0-9a-f]{0,4}:){,7}([0-9a-f]{0,4})((/[0-9]+)?)' | /bin/sed 's/^inet6 addr: //' | head -n1 | |
| fi | |
| } | |
| function bind { | |
| if [ "$1" == "*" ]; then | |
| echo "-c" # useless | |
| else | |
| echo "--bind-address=$1" | |
| fi | |
| } | |
| function loadImage { | |
| ip="$1" | |
| url="$2" | |
| wget -nv "$(bind "$ip")" -O /tmp/login-img.png -- "$url" | |
| } | |
| function login { | |
| ip="$1" | |
| date="$2" | |
| urls=$(wget -nv "$(bind "$ip")" -O - -- "$LOGIN_URL" | filterAuthImages ) | |
| urlsSucc=$? | |
| if [ "$urlsSucc" != 0 ]; then | |
| return $urlsSucc; | |
| fi | |
| mainUrl="$(printf "%s" "$urls" | head -n1)" | |
| additionalUrls="$(printf "%s" "$urls" | (read; cat))" | |
| echo "mainUrl: $mainUrl" | |
| echo "additionalUrls: $additionalUrls" | |
| loadImage "$ip" "$mainUrl" | |
| mainResult=$? | |
| ip6="$(getMyIp6)" | |
| for i in $additionalUrls; do | |
| loadImage "$ip6" "$i" || loadImage "$ip" "$i" | |
| done | |
| return $mainResult | |
| } | |
| function filterAuthImages { | |
| grep IPv | grep -oE '<img src="[^"]+"' | sed 's/"$//' | sed 's/^.*"//' | |
| } | |
| dhc | |
| date="$(fdate)" | |
| ip="$(getMyIp)" | |
| while | |
| [ "$ip" != "" ] && | |
| echo trying to log in... && ( ! login "$ip" "$date" ) | |
| do | |
| echo failed | |
| touch ~/"fadmin-$date.ERROR" | |
| sleep 5 | |
| dhc | |
| date="$(fdate)" | |
| ip="$(getMyIp)" | |
| done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment