La clé pour résoudre des problèmes comme celui-ci est de savoir comment poser la question. J'ai cherché sur Google à la recherche de "comment accéder au pain panera wifi" et j'ai trouvé ce joyau.
Cet article avait plusieurs scripts qui pourraient être utilisés pour faciliter la connexion automatique. J'ai choisi d'inclure l'exemple de Panera Bread qui exploite la bibliothèque Mechanize de Python.
La solution utilise le dispatcher.d
répertoire de NetworkManager pour exécuter des scripts chaque fois qu'une interface réseau particulière monte ou descend. L'article détaille un script que vous placeriez dans ce répertoire /etc/NetworkManager/dispatch.d
, appelé 07-autologin_openwifi
. Voici ce 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
Et voici le script pain 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 ---"
Je vous encourage à lire l'intégralité de l'article si vous êtes intéressé par d'autres méthodes pour effectuer la connexion automatique. L'article avait plusieurs autres réseaux WiFi ouverts qui ont été scriptés pour la région de Baltimore, MD.
wget
programme est-il installé?