def getwifi(wifilist, wificount):
wifi = pywifi.PyWiFi() # 抓取网卡接口
ifaces = wifi.interfaces()[0] # 获取网卡
ifaces.scan()
time.sleep(8)
bessis = ifaces.scan_results()
allwifilist = []
namelist = []
ssidlist = []
for data in bessis:
if data.ssid not in namelist: # 去掉重复的WIFI名称
namelist.append(data.ssid)
allwifilist.append((data.ssid, data.signal))
sorted(allwifilist, key=lambda st: st[1], reverse=True)
time.sleep(1)
n = 0
if len(allwifilist) is not 0:
for item in allwifilist:
if (item[0] not in ssidlist) & (item[0] not in wifilist):
n = n + 1
if n <= wificount:
ssidlist.append(item[0])
print(allwifilist)
return ssidlist