La chiave per risolvere problemi come questo è sapere come porre la domanda. Ho cercato Google cercando "come accedere a panera bread wifi" e ho trovato questo gioiello.
Questo articolo aveva diversi script che potevano essere usati per facilitare l'accesso automatico. Ho scelto di includere l'esempio per Panera Bread che sfrutta la libreria Mechanize di Python.
La soluzione utilizza la dispatcher.d
directory di NetworkManager per eseguire script ogni volta che una particolare interfaccia di rete va su o giù. L'articolo descrive in dettaglio uno script da inserire in questa directory /etc/NetworkManager/dispatch.d
, chiamato 07-autologin_openwifi
. Ecco quello script:
#!/bin/bash
#------------------------------
# By Fahad Alduraibi
# Last update: June 12, 2012
# Version: 1.1
#------------------------------
export LC_ALL=C
LogFile="/var/log/07-WIFI_ACCESS.log"
# The parameters that get passed to the script are:
# $1 = The interface name ( eth0, wlan0 ...etc)
# $2 = Interface status ( "up" or "down" )
# Check if wireless status is up
# I have two wifi cards in my laptop, named "wlan0 and wlan1"
# so I use regular expression "wlan[01]" to match both of them.
if [[ "$1" =~ wlan[01] && $2 == "up" ]]; then
# Get the network name from "iwconfig" or (can also locate the network based on IP or MAC address if needed)
ESSID=$(/sbin/iwconfig $1 | grep ESSID | cut -d'"' -f2)
# Record the date and time for debugging purposes only
echo "[`date`] ESSID=($ESSID)" >> $LogFile
# If the wireless name matches then run its python script
if [[ "$ESSID" == "BCPL-PUBLIC-WIFI" ]]; then
/usr/bin/python /myscripts/baltimore-county_library_wifi.py 1>> $LogFile 2>&1
elif [[ "$ESSID" == "PANERA" ]]; then
/usr/bin/python /myscripts/panera.py 1>> $LogFile 2>&1
elif [[ "$ESSID" == "Nordstrom_Wi-Fi" ]]; then
/usr/bin/python /myscripts/nordstrom.py 1>> $LogFile 2>&1
#elif .... (you can add more open wifi here)
fi
fi
#if [[ "$1" =~ wlan[01] && $2 == "down" ]]; then
##If you want to do somehting when the network is down
#fi
Ed ecco la sceneggiatura del pane Panera panera.py
:
#------------------------------
# By Fahad Alduraibi
# Last update: June 12, 2012
# Version: 1.1
#------------------------------
import mechanize
import sys
br = mechanize.Browser()
br.set_handle_equiv(True)
#br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20100101 Firefox/13.0')]
testURL = 'http://fadvisor.net/blog/'
response = br.open(testURL)
if response.geturl() == testURL:
print "FAD: You are already logged in to Panera."
sys.exit()
try:
forms = mechanize.ParseResponse(response, backwards_compat=False)
except:
print "FAD: Error in parsing forms, Am I already logged in to Panera?"
sys.exit()
response.close
form = forms[0]
#print form
#print "----------------------------------- Login"
request = form.click()
response = mechanize.urlopen(request)
forms = mechanize.ParseResponse(response, backwards_compat=False)
response.close()
form = forms[0]
#print form
#print "----------------------------------- Validate"
#print
request = form.click()
response = mechanize.urlopen(request)
forms = mechanize.ParseResponse(response, backwards_compat=False)
response.close()
form = forms[0]
#print form
#print "----------------------------------- ConfirmLogin New"
#print
request = form.click()
response = mechanize.urlopen(request)
forms = mechanize.ParseResponse(response, backwards_compat=False)
response.close()
form = forms[0]
#print form
#print "----------------------------------- ConfirmLogin Validate"
#print
request = form.click()
response = mechanize.urlopen(request)
forms = mechanize.ParseResponse(response, backwards_compat=False)
response.close()
form = forms[0]
#print form
#print "----------------------------------- CompleteLogin New"
#print
request = form.click()
response = mechanize.urlopen(request)
forms = mechanize.ParseResponse(response, backwards_compat=False)
response.close()
form = forms[0]
#print form
#print "----------------------------------- HttpLoginRequest"
#print
request = form.click()
response = br.open(request)
#print response.read()
response.close()
print "--- Panera Done ---"
Ti incoraggio a leggere l'intero articolo se sei interessato ad altri metodi per eseguire l'accesso automatico. L'articolo aveva diverse altre reti WiFi aperte che erano state programmate per l'area di Baltimora, MD.
wget
programma è installato?