不允许NetworkManager扫描

时间:2016-09-01 14:48:10

标签: python linux arm dbus

我正在使用dbus api for NetworkManager 1.4.0 with python wrapper。这段代码扫描wifi网络:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import NetworkManager as NM

def ap_sec_to_str2(sec):
    list = []

    if sec & (0x1 | 0x2 | 0x10 | 0x20):
        list.append("WEP")
    if sec & (0x4 | 0x40):
        list.append("WPA")
    if sec & (0x8 | 0x80):
        list.append("WPA2")
    if sec & 0x100:
        list.append("PSK")
    if sec & 0x200:
        list.append("802.1X")

    return list

def MHZ2Chan(mhz):
    return {
        2412: 1,
        2417: 2,
        2422: 3,
        2427: 4,
        2432: 5,
        2437: 6,
        2442: 7,
        2447: 8,
        2452: 9,
        2457: 10,
        2462: 11,
        2467: 12,
        2472: 13,
        2484: 14
    }.get(mhz)

"""WIFI NetwokList"""
def APList(iface):
    check = lambda dev: dev.DeviceType == NM.NM_DEVICE_TYPE_WIFI and dev.Interface == iface
    dev = next( (dev for dev in NM.NetworkManager.GetDevices() if check(dev) ))
    rslt = []
    dev = dev.SpecificDevice()
    dev.RequestScan({}) #this is wrong!!! 
    for ap in dev.GetAllAccessPoints():
        info = {
            'ssid': ap.Ssid,
            'channel': MHZ2Chan(ap.Frequency),
            'level': ap.Strength,
            'security': ap_sec_to_str2(ap.WpaFlags | ap.RsnFlags)
        }
        rslt.append(info)
    return rslt

如果我经常调用此函数,有时会发生错误

org.freedesktop.NetworkManager.Device.NotAllowed:Scanningnotallowedimmediatelyfollowingpreviousscan. 

是否是硬件功能?

平台 ARM CortexA9 Yocto 1.6

WIFI usb加密狗:

ID 20f4:648b TRENDnetTEW-648UBM802.11n150MbpsMicroWirelessNAdapter[RealtekRTL8188CUS]

0 个答案:

没有答案