Automatyczne logowanie do Vodafone Community WiFi (Fon) za pomocą skryptu Unix

6

Najpierw muszę powiedzieć, że moje pytanie jest podobne do tego

Używam AP Vodafone Community Fon i często się rozłącza. W OS X, którego używam, istnieje narzędzie o nazwie Captive Network Assistant do łączenia się z tymi punktami dostępowymi. Wykonuje zadanie, ale niestety nie zachowuje nazwy użytkownika / hasła (otworzyłem raport o błędach w Apple), więc za każdym razem muszę je wpisywać ponownie.

Mam zainstalowane curl, lynx, wget, ale jestem tym narzędziem. I mogę uzyskać wszystko, czego potrzeba za pośrednictwem Macport. W Google Chrome zidentyfikowałem kilka adresów URL do logowania, ale żaden nie działał. Przynajmniej nie mogłem sprawić, żeby działały. Oto kilka próbek:

To jest początkowy adres URL:

https://it.portal.vodafone-wifi.com/jcp/it?res=welcome&nasid=90-55-6E-E5-E0-60&uamip=192.168.6.1&uamport=80&mac=00-19-E3-33-E0 -72 i wyzwanie = bd551b56b4a5 ...... 26061f111ceaf & ip = 192.168.6.2 i userurl = http% 3A% 2F% 2Fwww.google.com & lang = it & LANGUAGE = it

To adres URL, który powinien faktycznie się zalogować:

http://192.168.6.1/logon?username=FON%2FVF_IT%2F < USER >% 40 < DOMAIN > & password = 6223980fe ........ 93ea753ef4de

Gdzie USER to nazwa użytkownika, DOMAIN domeny adresu e-mail. Ze względów bezpieczeństwa zmieniłem niektóre cyfry z kropkami w polu hasła, które mogą być szyfrowaniem hasła, którego używam.

Próbowałem przekazać dane uwierzytelniające za pomocą wget / curl / lynx, ale zawsze otrzymuję zwrotny adres URL z „BŁĘDNYM HASŁEM” w łączu.

Czy ktoś ma na to rozwiązanie?

Michele Dall'Agata
źródło

Odpowiedzi:

3

W końcu znalazłem rozwiązanie. Połączenie może wymagać kilku pętli, ale na końcu uwierzytelnia się. Działa na systemie OS X El Capitan 10.11.4, wszelkie modyfikacje poprzednich wersji OS X (w razie potrzeby) lub Linuksa powinny być łatwe.

Strzeż się, że musi mieć zainstalowanego „wget” w $ PATH.

Aby uruchomić skrypt jako agent użytkownika OS X przy logowaniu, sprawdź to . Oto skrypt:

#!/bin/sh

######################################################################
#
# OS X Script to automatically reconnect to a Vodafone Community AP
# when the connection drops.
#
# It's designed to support to be launched as an OS X login agent
# logging to the console.
# 
# Tested only on OS X EL Capitan. It should also run on Linux without
# many modifications
#
# Version 3.0
# Author: Michele Dall'Agata
#
# CHANGELOG:
#
# v3.0: All connection parameters are automatically retrieved from the 
#       Vodafone Station.
#       Force the use of Vodafone-WiFi APs.
#       Cleaner log.
# v2.2: Check after restarting the WiFi if the connection is up and continue
#       in case. It happens quite often.
# v2.1: All references to the WiFi interface now correctly use $WIFI_IF.
# v2.0: Reorganized the logic.
#       Added section OS X specific.
#       Loop waiting for WiFi connecting after restarting.
#       Added $WIFI_IF variable for WiFi interface.
#       Check if it is a Vodafone Community AP.
#       Fixed all wget commands.
#       Complete although stripped logging. Now it's clearer which step
#       is executed.
# v1.1: Restarts the WiFi interface.
# v1.0: first working skeleton. Hey, it did the job! :)
#
######################################################################


# $PATH should include the location where wget is installed
export PATH=$PATH:/opt/local/bin

# The Vodafone Country code. This is the code for Italy
COUNTRY=VF_IT

# The URL uses "%40" for "@". We do the same
USERNAME=<Your username>%40<Your domain>
PASSWORD=<Your Password>

# This will be visible in the Console app
# Set it to /dev/null if you don't want any log
LOGFILE=~/Library/Logs/Vodafone.log

# WiFi network interface. Option+Click on WiFI icon to get the one on
# your Mac. Change it accordingly.
WIFI_IF=en0

######################################################################
# For reference only. They get automatically set by the script
#

# MAC address of the Vodafone Station. 
NASID=
# MAC address of your WiFi interface. 
MACADDR=
# Vodafone Station (gateway) IP address.
IPADDR=


#######################################################################
# Begin Script
#######################################################################

# Log beginning of execution
echo >> $LOGFILE
echo $(date "+%d %b %H:%M:%S") Starting Vodafone Connection agent >> $LOGFILE

while [ true ]
do

# If the WiFi is switched off do nothing.  Otherwise check if we are connected to
# a captive network

    ! ifconfig $WIFI_IF | grep  "RUNNING" || \
        wget -qO- http://captive.apple.com/hotspot-detect.html 2>&1 | \
        grep 'Success' >> /dev/null

    if [ $?  != 0 ]; then

        echo $(date "+%d %b %H:%M:%S") >> $LOGFILE
        echo $(date "+%d %b %H:%M:%S") Connection is down. Reauthenticating >> $LOGFILE

# This is OS X specific
        if [ $(uname) == "Darwin" ]; then

# Turn WiFi off and on in case the connection has got stuck (exclamation mark on WiFi icon)
            echo $(date "+%d %b %H:%M:%S") Switching WiFi Off >> $LOGFILE
            networksetup -setairportpower $WIFI_IF off

            echo $(date "+%d %b %H:%M:%S") Switching WiFi On >> $LOGFILE
            networksetup -setairportpower $WIFI_IF on

# We are here to reconnect to a Vodafone Community netwok.      
            networksetup -setairportnetwork $WIFI_IF Vodafone-WiFi

# Wait for the WiFi to connect to the router and get an IP address
            while ! ifconfig $WIFI_IF | grep  "inet " 2>&1 > /dev/null ; do
                echo $(date "+%d %b %H:%M:%S") Waiting for WiFi to connect >> $LOGFILE
                networksetup -setairportnetwork $WIFI_IF Vodafone-WiFi
                sleep 1
            done
            sleep 2

The connection may be up already. Check and in case loop again
            wget -qO- http://captive.apple.com/hotspot-detect.html 2>&1 | grep 'Success' > /dev/null && \
                echo $(date "+%d %b %H:%M:%S") The connection is up and running\! >> $LOGFILE && \
                continue

# This could be at the beginning of the loop but the connection was down 
# so restarting the WiFi interface may help anyway.

# TODO: To check what happens if we use a different a different network
            if [ $(networksetup -getairportnetwork $WIFI_IF | awk '{print $NF}') != "Vodafone-WiFi" ];
            then
                echo $(date "+%d %b %H:%M:%S") Not a Vodafone AP
                sleep 60
                continue
            fi

        fi
#
# if Captive Network Assistant app launches for some reason DNS doesn't work.
# Just kill it

        pgrep "Captive Network Assistant" && echo $(date "+%d %b %H:%M:%S") Killed Captive Network Assistant.. \
            $(killall -9 "Captive Network Assistant" 2>&1) >> $LOGFILE

# We can get all needed parameters from the returned URL.
# Grab them querying any IP number and store them in $IPPARM

        IPPARM=$(wget -qO- --timeout=10 -t 1 8.8.8.8 2>&1 | grep loginVodafone | grep -i challenge | \
            sed -e 's/\&/=/g' | awk -F= '{ print $7 " " $9 " " $13 " " $15}')

# Assign each value
        read NASID IPADDR MACADDR CHALLENGE <<< $IPPARM

# If empty either the Captive Network Assistant deamon restored the connection or something went wrong. 
# Loop again

        if [ -z $CHALLENGE ]; then
            echo $(date "+%d %b %H:%M:%S") The station returned no login URL. The connection may be up. \
                >> $LOGFILE
        else

# Kill it again...
            pgrep "Captive Network Assistant" && echo $(date "+%d %b %H:%M:%S") Killed Captive Network Assistant.. \
                $(killall -9 "Captive Network Assistant" 2>&1) >> $LOGFILE
            echo $(date "+%d %b %H:%M:%S") Connecting to AP $IPADDR with BSSID $NASID >> $LOGFILE

            wget -qO-  --timeout=10 --keep-session-cookies \
                --post-data "chooseCountry=$COUNTRY%2F&userFake=$USERNAME$&UserName=$COUNTRY%2F$USERNAME&Password=$PASSWORD&_rememberMe=on" \
                "https://it.portal.vodafone-wifi.com/jcp/it?res=login&nasid=$NASID&uamip=$IPADDR&uamport=80&mac=$MACADDR&challenge=$CHALLENGE" \
                2>&1 >> /dev/null
        fi

# It may need some time to fully establish the connection?
        sleep 3

# And kill it again...
        pgrep "Captive Network Assistant" && echo $(date "+%d %b %H:%M:%S") Killed Captive Network Assistant.. \
            $(killall -9 "Captive Network Assistant" 2>&1) >> $LOGFILE

# Log if the connection was re-established
        (wget -qO- http://captive.apple.com/hotspot-detect.html 2>&1 | grep 'Success' > /dev/null && \
            echo $(date "+%d %b %H:%M:%S") The connection is up and running\! >> $LOGFILE) || \
            echo $(date "+%d %b %H:%M:%S") The connection is still down. Retrying >> $LOGFILE

    else

# No need for more than 1s. When the connection is up it's just 1 HTTP query per loop.
        sleep 1
    fi
done
Michele Dall'Agata
źródło