解决诸如此类问题的关键是知道如何提出问题。我在Google上搜索了“如何访问Panera Bread wifi”,然后打开了这个宝石。
本文提供了一些可用于促进自动登录的脚本。我选择包括Panera Bread的示例,该示例利用了Python的Mechanize库。
该解决方案利用NetworkManager的dispatcher.d
目录在特定网络接口出现故障时随时运行脚本。本文详细介绍了您将在此目录中放置的脚本/etc/NetworkManager/dispatch.d
,名为07-autologin_openwifi
。这是脚本:
#!/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
这是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 ---"
如果您对执行自动登录的其他方法感兴趣,建议您阅读整篇文章。该文章还有其他几个开放的WiFi网络,这些网络是为马里兰州巴尔的摩市编写的。
wget
安装程序?