10 def __init__(self, hostname, username, password):
15 def fetch(self, url, args=None):
16 req = urllib2.Request(url)
17 base64string = base64.encodestring(
"%s:%s" % (self.
username, self.
password))[:-1]
19 req.add_header(
"Authorization",
"Basic %s" % base64string)
21 req.data = urllib.urlencode(args)
23 fp = urllib2.urlopen(req)
30 url =
"http://%s/apply.cgi" % self.
hostname 33 args[
"submit_button"]=
"Wireless_Basic" 34 args[
"action"]=
"ApplyTake" 35 args[
"change_action"]=
"gozila_cgi" 36 args[
"submit_type"]=
"save" 37 args[
"wl0_nctrlsb"]=
"" 38 args[
"wl1_nctrlsb"]=
"" 40 args[
"wl0_mode"]=
"sta" 41 args[
"wl0_net_mode"]=
"n-only" 42 args[
"wl0_ssid"]=essid
43 args[
"wl0_distance"]=
"500" 44 args[
"eth1_bridged"]=
"1" 45 args[
"eth1_multicast"]=
"0" 47 args[
"eth1_ipaddr"]=
"4" 48 args[
"eth1_ipaddr_0"]=
"0" 49 args[
"eth1_ipaddr_1"]=
"0" 50 args[
"eth1_ipaddr_2"]=
"0" 51 args[
"eth1_ipaddr_3"]=
"0" 52 args[
"eth1_netmask"]=
"4" 53 args[
"eth1_netmask_0"]=
"0" 54 args[
"eth1_netmask_1"]=
"0" 55 args[
"eth1_netmask_2"]=
"0" 56 args[
"eth1_netmask_3"]=
"0" 58 args[
"wl1_net_mode"]=
"disabled" 59 args[
"wl1_ssid"]=
"dd-wrt" 60 args[
"wl1_closed"]=
"0" 61 args[
"wl1_distance"]=
"2000" 62 args[
"eth2_bridged"]=
"1" 63 args[
"eth2_multicast"]=
"0" 65 args[
"eth2_ipaddr"]=
"4" 66 args[
"eth2_ipaddr_0"]=
"0" 67 args[
"eth2_ipaddr_1"]=
"0" 68 args[
"eth2_ipaddr_2"]=
"0" 69 args[
"eth2_ipaddr_3"]=
"0" 70 args[
"eth2_netmask"]=
"4" 71 args[
"eth2_netmask_0"]=
"0" 72 args[
"eth2_netmask_1"]=
"0" 73 args[
"eth2_netmask_2"]=
"0" 74 args[
"eth2_netmask_3"]=
"0" 76 body = self.
fetch(url, args)
79 url =
"http://%s/Status_Wireless.live.asp" % self.
hostname 80 body = self.
fetch(url)
83 lines = body.split(
"\n")
88 line = line.replace(
" ",
"")
89 parts = line.split(
"::", 1)
91 d[parts[0]] = parts[1]
93 essid = d.get(
'wl_ssid',
'')
94 wl_channel = d.get(
'wl_channel',
'').split()[0]
95 channel = int(wl_channel)
96 rate = d.get(
'wl_rate',
'')
103 tx_power = d.get(
'wl_xmit',
'')
105 active_wireless = d.get(
'active_wireless',
None)
107 active_wireless = active_wireless.replace(
"'",
"")
108 parts = active_wireless.split(
",")
112 signal = int(parts[4])
113 noise = int(parts[5])
115 quality = signal * 1.24 + 116
117 signal = int(parts[5])
118 noise = int(parts[6])
120 quality = int(parts[8])/10
125 url =
"http://%s/Site_Survey.asp" % self.
hostname 127 body = self.
fetch(url)
129 lines = body.split(
"\n")
130 for i
in range(len(lines)):
131 if lines[i].startswith(
"var table = "):
135 for j
in range(i+1, len(lines)):
136 if lines[j].startswith(
");"):
break 137 line = lines[j].strip()
138 if not line:
continue 139 if line[0] ==
",": line = line[1:]
145 fp = StringIO.StringIO(string.join(aplines,
'\n'))
146 reader = csv.reader(fp)
150 channel = int(row[3])
157 for ap, row
in aps.items():
158 print ap, row[8][:20]
161 def main(argv, stdout, environ):
162 progname = sys.argv[0]
163 optlist, args = getopt.getopt(argv[1:],
"", [
"help"])
165 dd =
DDWRT(
"192.168.1.1",
"root",
"admin")
174 elif cmd ==
"survey":
177 if __name__ ==
"__main__":
178 main(sys.argv, sys.stdout, os.environ)
def __init__(self, hostname, username, password)
def main(argv, stdout, environ)
def fetch(self, url, args=None)