La clave para resolver problemas como este es saber cómo hacer la pregunta. Busqué en Google buscando "cómo acceder a panera bread wifi" y encontré esta joya.
Este artículo tenía varios scripts que podrían usarse para facilitar el inicio de sesión automático. Opté por incluir el ejemplo de Panera Bread que aprovecha la biblioteca Mechanize de Python.
La solución utiliza el dispatcher.d
directorio de NetworkManager para ejecutar scripts cada vez que una interfaz de red en particular sube o baja. El artículo detalla una secuencia de comandos que colocaría en este directorio /etc/NetworkManager/dispatch.d
, llamada 07-autologin_openwifi
. Aquí está ese guión:
#!/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
Y aquí está el script de pan 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 ---"
Le recomiendo que lea el artículo completo si está interesado en otros métodos para iniciar sesión automáticamente. El artículo tenía varias otras redes WiFi abiertas que estaban programadas para el área de Baltimore, MD.
wget
programa instalado?