以下代码尝试提取所有附近AP的MAC地址,然后将它们保存在矩阵中,我不知道出了什么问题。它使用库python-wifi 0.6.1。这是代码和错误:
`
import errno
import sys
import types
import pythonwifi.flags
from pythonwifi.iwlibs import Wireless, WirelessInfo, Iwrange, getNICnames, getWNICnames
i=0
ArregloMAC=[20][30]
wifi= Wireless('wlan0')
results = wifi.scan()
(num_channels, frequencies) = wifi.getChannelInfo()
print "%-8.16s Scan completed :" % (wifi.ifname, )
for ap in results:
index = 1
ArregloMAC[i][index-1]= str("%d-%s" % (_, ap.bssid))
index = index+1
print ArregloMAC`
IndexError:列表索引超出范围
答案 0 :(得分:0)
这一行
ArregloMAC=[20][30]
会直接给你一个超出范围的指数。它的含义是,创建一个元素列表[20]
,然后获取该列表的第31个元素,并将其分配给ArregloMAC
。由于列表只有一个元素,因此不可避免地会出错。
看起来你正在尝试声明一个二维数组。这不是Python列表的工作方式。