使用Python检索Windows附近的无线局域网网络的信号强度RSSI

1. 如果你是在Windows上,你可能想使用WLAN API,它提供了“WlanGetAvailableNetworkList()函数(参见API文档,我不知道有任何Python包装的WLANAPI.DLL所以你可能需要把它包ctypes的。我做这个(作品-)初步的脚本,但它可能是这些混沌。您将要阅读理解所有的字段:

from ctypes import *
from ctypes.wintypes import *
from sys import exit

def customresize(array, new_size):
 return (array._type_*new_size).from_address(addressof(array))

wlanapi = windll.LoadLibrary(‘wlanapi.dll‘)

ERROR_SUCCESS = 0

class GUID(Structure):
 _fields_ = [
  (‘Data1‘, c_ulong),
  (‘Data2‘, c_ushort),
  (‘Data3‘, c_ushort),
  (‘Data4‘, c_ubyte*8),
  ]

WLAN_INTERFACE_STATE = c_uint
(wlan_interface_state_not_ready,
 wlan_interface_state_connected,
 wlan_interface_state_ad_hoc_network_formed,
 wlan_interface_state_disconnecting,
 wlan_interface_state_disconnected,
 wlan_interface_state_associating,
 wlan_interface_state_discovering,
 wlan_interface_state_authenticating) = map(WLAN_INTERFACE_STATE, xrange(0, 8))

class WLAN_INTERFACE_INFO(Structure):
 _fields_ = [
  ("InterfaceGuid", GUID),
  ("strInterfaceDescription", c_wchar * 256),
  ("isState", WLAN_INTERFACE_STATE)
  ]

class WLAN_INTERFACE_INFO_LIST(Structure):
 _fields_ = [
  ("NumberOfItems", DWORD),
  ("Index", DWORD),
  ("InterfaceInfo", WLAN_INTERFACE_INFO * 1)
  ]

WLAN_MAX_PHY_TYPE_NUMBER = 0x8
DOT11_SSID_MAX_LENGTH = 32
WLAN_REASON_CODE = DWORD
DOT11_BSS_TYPE = c_uint
(dot11_BSS_type_infrastructure,
 dot11_BSS_type_independent,
 dot11_BSS_type_any) = map(DOT11_BSS_TYPE, xrange(1, 4))
DOT11_PHY_TYPE = c_uint
dot11_phy_type_unknown  = 0
dot11_phy_type_any   = 0
dot11_phy_type_fhss   = 1
dot11_phy_type_dsss   = 2
dot11_phy_type_irbaseband = 3
dot11_phy_type_ofdm   = 4
dot11_phy_type_hrdsss  = 5
dot11_phy_type_erp   = 6
dot11_phy_type_ht   = 7
dot11_phy_type_IHV_start = 0x80000000
dot11_phy_type_IHV_end  = 0xffffffff 

DOT11_AUTH_ALGORITHM = c_uint
DOT11_AUTH_ALGO_80211_OPEN   = 1
DOT11_AUTH_ALGO_80211_SHARED_KEY = 2
DOT11_AUTH_ALGO_WPA    = 3
DOT11_AUTH_ALGO_WPA_PSK   = 4
DOT11_AUTH_ALGO_WPA_NONE   = 5
DOT11_AUTH_ALGO_RSNA    = 6
DOT11_AUTH_ALGO_RSNA_PSK   = 7
DOT11_AUTH_ALGO_IHV_START   = 0x80000000
DOT11_AUTH_ALGO_IHV_END   = 0xffffffff

DOT11_CIPHER_ALGORITHM = c_uint
DOT11_CIPHER_ALGO_NONE   = 0x00
DOT11_CIPHER_ALGO_WEP40   = 0x01
DOT11_CIPHER_ALGO_TKIP   = 0x02
DOT11_CIPHER_ALGO_CCMP   = 0x04
DOT11_CIPHER_ALGO_WEP104   = 0x05
DOT11_CIPHER_ALGO_WPA_USE_GROUP = 0x100
DOT11_CIPHER_ALGO_RSN_USE_GROUP = 0x100
DOT11_CIPHER_ALGO_WEP    = 0x101
DOT11_CIPHER_ALGO_IHV_START  = 0x80000000
DOT11_CIPHER_ALGO_IHV_END   = 0xffffffff 

WLAN_AVAILABLE_NETWORK_CONNECTED = 1
WLAN_AVAILABLE_NETWORK_HAS_PROFILE = 2

WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_ADHOC_PROFILES = 0x00000001
WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_MANUAL_HIDDEN_PROFILES = 0x00000002

class DOT11_SSID(Structure):
 _fields_ = [
  ("SSIDLength", c_ulong),
  ("SSID", c_char * DOT11_SSID_MAX_LENGTH)
  ]

class WLAN_AVAILABLE_NETWORK(Structure):
 _fields_ = [
  ("ProfileName", c_wchar * 256),
  ("dot11Ssid", DOT11_SSID),
  ("dot11BssType", DOT11_BSS_TYPE),
  ("NumberOfBssids", c_ulong),
  ("NetworkConnectable", c_bool),
  ("wlanNotConnectableReason", WLAN_REASON_CODE),
  ("NumberOfPhyTypes", c_ulong),
  ("dot11PhyTypes", DOT11_PHY_TYPE * WLAN_MAX_PHY_TYPE_NUMBER),
  ("MorePhyTypes", c_bool),
  ("wlanSignalQuality", c_ulong),
  ("SecurityEnabled", c_bool),
  ("dot11DefaultAuthAlgorithm", DOT11_AUTH_ALGORITHM),
  ("dot11DefaultCipherAlgorithm", DOT11_CIPHER_ALGORITHM),
  ("Flags", DWORD),
  ("Reserved", DWORD)
  ]

class WLAN_AVAILABLE_NETWORK_LIST(Structure):
 _fields_ = [
  ("NumberOfItems", DWORD),
  ("Index", DWORD),
  ("Network", WLAN_AVAILABLE_NETWORK * 1)
  ]

WlanOpenHandle = wlanapi.WlanOpenHandle
WlanOpenHandle.argtypes = (DWORD, c_void_p, POINTER(DWORD), POINTER(HANDLE))
WlanOpenHandle.restype = DWORD

WlanEnumInterfaces = wlanapi.WlanEnumInterfaces
WlanEnumInterfaces.argtypes = (HANDLE, c_void_p,
        POINTER(POINTER(WLAN_INTERFACE_INFO_LIST)))
WlanEnumInterfaces.restype = DWORD

WlanGetAvailableNetworkList = wlanapi.WlanGetAvailableNetworkList
WlanGetAvailableNetworkList.argtypes = (HANDLE, POINTER(GUID), DWORD, c_void_p,
          POINTER(POINTER(WLAN_AVAILABLE_NETWORK_LIST)))
WlanGetAvailableNetworkList.restype = DWORD

WlanFreeMemory = wlanapi.WlanFreeMemory
WlanFreeMemory.argtypes = [c_void_p]

if __name__ == ‘__main__‘:
 NegotiatedVersion = DWORD()
 ClientHandle = HANDLE()
 ret = WlanOpenHandle(1, None, byref(NegotiatedVersion), byref(ClientHandle))
 if ret != ERROR_SUCCESS:
  exit(FormatError(ret))
 # find all wireless network interfaces
 pInterfaceList = pointer(WLAN_INTERFACE_INFO_LIST())
 ret = WlanEnumInterfaces(ClientHandle, None, byref(pInterfaceList))
 if ret != ERROR_SUCCESS:
  exit(FormatError(ret))
 try:
  ifaces = customresize(pInterfaceList.contents.InterfaceInfo,
        pInterfaceList.contents.NumberOfItems)
  # find each available network for each interface
  for iface in ifaces:
   print "Interface: %s" % (iface.strInterfaceDescription)
   pAvailableNetworkList = pointer(WLAN_AVAILABLE_NETWORK_LIST())
   ret = WlanGetAvailableNetworkList(ClientHandle,
          byref(iface.InterfaceGuid),
          0,
          None,
          byref(pAvailableNetworkList))
   if ret != ERROR_SUCCESS:
    exit(FormatError(ret))
   try:
    avail_net_list = pAvailableNetworkList.contents
    networks = customresize(avail_net_list.Network,
          avail_net_list.NumberOfItems)
    for network in networks:
     print "SSID: %s, quality: %02d%%" % (
      network.dot11Ssid.SSID[:network.dot11Ssid.SSIDLength],
      network.wlanSignalQuality)
   finally:
    WlanFreeMemory(pAvailableNetworkList)
 finally:
  WlanFreeMemory(pInterfaceList)

在Linux上,你有两个选择: 标准选项是解析的输出iwlist -scan。但是,如果你当前连接到WLAN并没有作为root运行,它只返回当前连接的无线局域网。 如果你需要比这更多,最好的办法是查询无线管理器守护程序。在现代,Linux版本,这NetworkManager的,虽然WICD更受欢迎。这两个经理可以dbus。除非你可以控制哪些客户对他们的系统,你可能需要支持这两个选项,或者至少有一个选项,有一个后备iwlist

2. 那么你可以调用来获得(Linux的=iwlist),解析结果,并显示它。

3. @FMARK我只想说非常感谢你为这个职位。在我的工作中,我一直在试图从连接的AP在Windows中得到的RSSI,以及你应得千恩万谢终于得到了实现。目前,我列出了所有的接入点,但我正在修改它。我想提供一个对你的代码。我不是很有经验的C或Python的ctypes的模块,但我想我可能已经找到一个可能的错误。我真的不知道它有什么不同,但我注意到: 你定义的枚举是这样的:

DOT11_BSS_TYPE = c_uint
(dot11_BSS_type_infrastructure,
 dot11_BSS_type_independent,
 dot11_BSS_type_any) = map(DOT11_BSS_TYPE, xrange(1, 4))

但随后其他的定义很相似是这样的:

DOT11_PHY_TYPE = c_uint
dot11_phy_type_unknown  = 0
dot11_phy_type_any   = 0
dot11_phy_type_fhss   = 1
dot11_phy_type_dsss   = 2
dot11_phy_type_irbaseband = 3
dot11_phy_type_ofdm   = 4
dot11_phy_type_hrdsss  = 5
dot11_phy_type_erp   = 6
dot11_phy_type_ht   = 7
dot11_phy_type_IHV_start = 0x80000000
dot11_phy_type_IHV_end  = 0xffffffff 

我觉得第二snippit应仿照喜欢这一首,但我可能是错的。这里是我的主意:

DOT11_PHY_TYPE = c_uint
(dot11_phy_type_unknown,
 dot11_phy_type_any,
 dot11_phy_type_fhss,
 dot11_phy_type_dsss,
 dot11_phy_type_irbaseband,
 dot11_phy_type_ofdm,
 dot11_phy_type_hrdsss,
 dot11_phy_type_erp,
 dot11_phy_type_ht,
 dot11_phy_type_IHV_start,
 dot11_phy_type_IHV_end) = map(DOT11_PHY_TYPE,
        [0,0,1,2,3,4,
        5,6,7,0x80000000,
        0xffffffff])

这样这些值会得到正确映射到DOT11_PHY_TYPE。也许我错了,但对于未来的乡亲像我这样的,我只是想无论是偶然在这里是正确的:) 再次感谢,@FMARK。

4. 所以..我根据自己的@fmarks代码(这是一个活更安全,你应该添加WlanScan功能,否则的RSSI值不会刷新。 这里是我的扩展代码! 所有道具@fmarks!

# -*- coding:utf-8 -*- 

import time
from ctypes import *
from ctypes.wintypes import *
from sys import exit

def customresize(array, new_size):
    return (array._type_*new_size).from_address(addressof(array))

wlanapi = windll.LoadLibrary(‘wlanapi.dll‘)

ERROR_SUCCESS = 0

class GUID(Structure):
    _fields_ = [
      (‘Data1‘, c_ulong),
      (‘Data2‘, c_ushort),
      (‘Data3‘, c_ushort),
      (‘Data4‘, c_ubyte*8),
      ]

WLAN_INTERFACE_STATE = c_uint
(wlan_interface_state_not_ready,
 wlan_interface_state_connected,
 wlan_interface_state_ad_hoc_network_formed,
 wlan_interface_state_disconnecting,
 wlan_interface_state_disconnected,
 wlan_interface_state_associating,
 wlan_interface_state_discovering,
 wlan_interface_state_authenticating) = map(WLAN_INTERFACE_STATE, xrange(0, 8))

class WLAN_INTERFACE_INFO(Structure):
    _fields_ = [
      ("InterfaceGuid", GUID),
      ("strInterfaceDescription", c_wchar * 256),
      ("isState", WLAN_INTERFACE_STATE)
     ]

class WLAN_INTERFACE_INFO_LIST(Structure):
    _fields_ = [
     ("NumberOfItems", DWORD),
     ("Index", DWORD),
     ("InterfaceInfo", WLAN_INTERFACE_INFO * 1)
    ]

WLAN_MAX_PHY_TYPE_NUMBER = 0x8
DOT11_SSID_MAX_LENGTH = 32
WLAN_REASON_CODE = DWORD

DOT11_BSS_TYPE = c_uint
(dot11_BSS_type_infrastructure,
 dot11_BSS_type_independent,
 dot11_BSS_type_any) = map(DOT11_BSS_TYPE, xrange(1, 4))

DOT11_PHY_TYPE = c_uint
dot11_phy_type_unknown  = 0
dot11_phy_type_any   = 0
dot11_phy_type_fhss   = 1
dot11_phy_type_dsss   = 2
dot11_phy_type_irbaseband = 3
dot11_phy_type_ofdm   = 4
dot11_phy_type_hrdsss  = 5
dot11_phy_type_erp   = 6
dot11_phy_type_ht   = 7
dot11_phy_type_IHV_start = 0x80000000
dot11_phy_type_IHV_end  = 0xffffffff

DOT11_AUTH_ALGORITHM = c_uint
DOT11_AUTH_ALGO_80211_OPEN   = 1
DOT11_AUTH_ALGO_80211_SHARED_KEY = 2
DOT11_AUTH_ALGO_WPA    = 3
DOT11_AUTH_ALGO_WPA_PSK   = 4
DOT11_AUTH_ALGO_WPA_NONE   = 5
DOT11_AUTH_ALGO_RSNA    = 6
DOT11_AUTH_ALGO_RSNA_PSK   = 7
DOT11_AUTH_ALGO_IHV_START   = 0x80000000
DOT11_AUTH_ALGO_IHV_END   = 0xffffffff

DOT11_CIPHER_ALGORITHM = c_uint
DOT11_CIPHER_ALGO_NONE   = 0x00
DOT11_CIPHER_ALGO_WEP40   = 0x01
DOT11_CIPHER_ALGO_TKIP   = 0x02
DOT11_CIPHER_ALGO_CCMP   = 0x04
DOT11_CIPHER_ALGO_WEP104   = 0x05
DOT11_CIPHER_ALGO_WPA_USE_GROUP = 0x100
DOT11_CIPHER_ALGO_RSN_USE_GROUP = 0x100
DOT11_CIPHER_ALGO_WEP    = 0x101
DOT11_CIPHER_ALGO_IHV_START  = 0x80000000
DOT11_CIPHER_ALGO_IHV_END   = 0xffffffff

WLAN_AVAILABLE_NETWORK_CONNECTED = 1
WLAN_AVAILABLE_NETWORK_HAS_PROFILE = 2

WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_ADHOC_PROFILES = 0x00000001
WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_MANUAL_HIDDEN_PROFILES = 0x00000002

class DOT11_SSID(Structure):
    _fields_ = [
     ("SSIDLength", c_ulong),
     ("SSID", c_char * DOT11_SSID_MAX_LENGTH)
    ]

class WLAN_AVAILABLE_NETWORK(Structure):
    _fields_ = [
     ("ProfileName", c_wchar * 256),
     ("dot11Ssid", DOT11_SSID),
     ("dot11BssType", DOT11_BSS_TYPE),
     ("NumberOfBssids", c_ulong),
     ("NetworkConnectable", c_bool),
     ("wlanNotConnectableReason", WLAN_REASON_CODE),
     ("NumberOfPhyTypes", c_ulong),
     ("dot11PhyTypes", DOT11_PHY_TYPE * WLAN_MAX_PHY_TYPE_NUMBER),
     ("MorePhyTypes", c_bool),
     ("wlanSignalQuality", c_ulong),
     ("SecurityEnabled", c_bool),
     ("dot11DefaultAuthAlgorithm", DOT11_AUTH_ALGORITHM),
     ("dot11DefaultCipherAlgorithm", DOT11_CIPHER_ALGORITHM),
     ("Flags", DWORD),
     ("Reserved", DWORD)
    ]

class WLAN_AVAILABLE_NETWORK_LIST(Structure):
    _fields_ = [
     ("NumberOfItems", DWORD),
     ("Index", DWORD),
     ("Network", WLAN_AVAILABLE_NETWORK * 1)
    ]

DOT11_MAC_ADDRESS = c_ubyte * 6

DOT11_CIPHER_ALGORITHM = c_uint
DOT11_CIPHER_ALGO_NONE   = 0x00
DOT11_CIPHER_ALGO_WEP40   = 0x01
DOT11_CIPHER_ALGO_TKIP   = 0x02

DOT11_PHY_TYPE = c_uint
DOT11_PHY_TYPE_UNKNOWN = 0
DOT11_PHY_TYPE_ANY   = 0
DOT11_PHY_TYPE_FHSS  = 1
DOT11_PHY_TYPE_DSSS  = 2
DOT11_PHY_TYPE_IRBASEBAND = 3
DOT11_PHY_TYPE_OFDM  = 4
DOT11_PHY_TYPE_HRDSSS  = 5
DOT11_PHY_TYPE_ERP   = 6
DOT11_PHY_TYPE_HT   = 7
DOT11_PHY_TYPE_IHV_START = 0X80000000
DOT11_PHY_TYPE_IHV_END  = 0XFFFFFFFF

class WLAN_RATE_SET(Structure):
    _fields_ = [
     ("uRateSetLength", c_ulong),
     ("usRateSet", c_ushort * 126)
    ]

class WLAN_BSS_ENTRY(Structure):
    _fields_ = [
     ("dot11Ssid",DOT11_SSID),
     ("uPhyId",c_ulong),
     ("dot11Bssid", DOT11_MAC_ADDRESS),
     ("dot11BssType", DOT11_BSS_TYPE),
     ("dot11BssPhyType", DOT11_PHY_TYPE),
     ("lRssi", c_long),
     ("uLinkQuality", c_ulong),
     ("bInRegDomain", c_bool),
     ("usBeaconPeriod",c_ushort),
     ("ullTimestamp", c_ulonglong),
     ("ullHostTimestamp",c_ulonglong),
     ("usCapabilityInformation",c_ushort),
     ("ulChCenterFrequency", c_ulong),
     ("wlanRateSet",WLAN_RATE_SET),
     ("ulIeOffset", c_ulong),
     ("ulIeSize", c_ulong)]

class WLAN_BSS_LIST(Structure):
    _fields_ = [
     ("TotalSize", DWORD),
     ("NumberOfItems", DWORD),
     ("NetworkBSS", WLAN_BSS_ENTRY * 1)
    ]

class WLAN_AVAILABLE_NETWORK_LIST_BSS(Structure):
    _fields_ = [
     ("TotalSize", DWORD),
     ("NumberOfItems", DWORD),
     ("Network", WLAN_BSS_ENTRY * 1)
    ]

WlanOpenHandle = wlanapi.WlanOpenHandle
WlanOpenHandle.argtypes = (DWORD, c_void_p, POINTER(DWORD), POINTER(HANDLE))
WlanOpenHandle.restype = DWORD

WlanCloseHandle = wlanapi.WlanCloseHandle
WlanCloseHandle.argtypes = (HANDLE, c_void_p)
WlanCloseHandle.restype = DWORD

WlanEnumInterfaces = wlanapi.WlanEnumInterfaces
WlanEnumInterfaces.argtypes = (HANDLE, c_void_p,
        POINTER(POINTER(WLAN_INTERFACE_INFO_LIST)))
WlanEnumInterfaces.restype = DWORD

WlanGetAvailableNetworkList = wlanapi.WlanGetAvailableNetworkList
WlanGetAvailableNetworkList.argtypes = (HANDLE, POINTER(GUID), DWORD, c_void_p,
          POINTER(POINTER(WLAN_AVAILABLE_NETWORK_LIST)))
WlanGetAvailableNetworkList.restype = DWORD

WlanGetNetworkBssList = wlanapi.WlanGetNetworkBssList
WlanGetNetworkBssList.argtypes = (HANDLE, POINTER(GUID),POINTER(GUID),POINTER(GUID), c_bool, c_void_p,
         POINTER(POINTER(WLAN_BSS_LIST)))
WlanGetNetworkBssList.restype = DWORD

WlanFreeMemory = wlanapi.WlanFreeMemory
WlanFreeMemory.argtypes = [c_void_p]

WlanScan = wlanapi.WlanScan
WlanScan.argtypes = (HANDLE, POINTER(GUID),c_void_p,c_void_p, c_void_p)
WlanScan.restype = DWORD

def get_interface():

    NegotiatedVersion = DWORD()
    ClientHandle = HANDLE()
    ret = WlanOpenHandle(1, None, byref(NegotiatedVersion), byref(ClientHandle))
    if ret != ERROR_SUCCESS:
        exit(FormatError(ret))
        # find all wireless network interfaces
    pInterfaceList = pointer(WLAN_INTERFACE_INFO_LIST())
    ret = WlanEnumInterfaces(ClientHandle, None, byref(pInterfaceList))
    if ret != ERROR_SUCCESS:
        exit(FormatError(ret))
    try:
        ifaces = customresize(pInterfaceList.contents.InterfaceInfo,
        pInterfaceList.contents.NumberOfItems)
    # find each available network for each interface
        for iface in ifaces:
        #print "Interface: %s" % (iface.strInterfaceDescription)
            interface = iface.strInterfaceDescription

    finally:
        WlanFreeMemory(pInterfaceList)
    return interface

class MAC_BSSID_POWER:
    """Classe para os valores retirados"""
    def __init__(self, mac, bssid):

        self.mac = str(mac)
        self.bssid = str(bssid)
        self.valores = []

    def addPower(self,power):
        self.valores.append(int(power))

    def getBssid(self):
        return self.bssid
    def getPowers(self):
        return self.valores
    def getMac(self):
        return self.mac

def get_BSSI():

    BSSI_Values={}

    NegotiatedVersion = DWORD()
    ClientHandle = HANDLE()
    ret = WlanOpenHandle(1, None, byref(NegotiatedVersion), byref(ClientHandle))
    if ret != ERROR_SUCCESS:
        exit(FormatError(ret))
        # find all wireless network interfaces
    pInterfaceList = pointer(WLAN_INTERFACE_INFO_LIST())
    ret = WlanEnumInterfaces(ClientHandle, None, byref(pInterfaceList))
    if ret != ERROR_SUCCESS:
        exit(FormatError(ret))
    try:
        ifaces = customresize(pInterfaceList.contents.InterfaceInfo,
           pInterfaceList.contents.NumberOfItems)
        # find each available network for each interface
        for iface in ifaces:
            # print "Interface: %s" % (iface.strInterfaceDescription)

            pAvailableNetworkList2 = pointer(WLAN_BSS_LIST())

            ret2 = WlanGetNetworkBssList(ClientHandle,
                    byref(iface.InterfaceGuid),
                    None,
                    None,True,None,
                    byref(pAvailableNetworkList2))
        if ret2 != ERROR_SUCCESS:
            exit(FormatError(ret2))
        try:
            retScan = WlanScan(ClientHandle,byref(iface.InterfaceGuid),None,None,None)
            if retScan != ERROR_SUCCESS:
                exit(FormatError(retScan))
            avail_net_list2 = pAvailableNetworkList2.contents
            networks2 = customresize(avail_net_list2.NetworkBSS,
                                  avail_net_list2.NumberOfItems)

            for network in networks2:

                SSID = str(network.dot11Ssid.SSID[:network.dot11Ssid.SSIDLength])
                BSSID = ‘:‘.join(‘%02x‘ % b for b in network.dot11Bssid).upper()
                signal_strength = str(network.lRssi)

                # print "SSID: " + SSID + " BSSID: "+ BSSID+ " SS: "+signal_strength

                BSSI_Values[BSSID] = [SSID,signal_strength]

                #print "Total "+str(len(networks2))
                #print BSSI_Values

        finally:
            WlanFreeMemory(pAvailableNetworkList2)
            WlanCloseHandle(ClientHandle,None)
    finally:
        WlanFreeMemory(pInterfaceList)
    return BSSI_Values

def get_BSSI_times_and_total_seconds(times,seconds):

    BSSI_to_return = {}

    for i in range(0,seconds*times):
        time_to_sleep = float(1.0/times)
        time.sleep(time_to_sleep)
        got_bssi_temp = get_BSSI()

        for bssi in got_bssi_temp:
            if not BSSI_to_return.get(bssi):
                BSSI_to_return[bssi] = MAC_BSSID_POWER(bssi,got_bssi_temp[bssi][0])
                BSSI_to_return[bssi].addPower( got_bssi_temp[bssi][1] )

                #BSSI_to_return[bssi] = [got_bssi_temp[bssi][1]]

            else:
                BSSI_to_return[bssi].addPower( got_bssi_temp[bssi][1] )
                #BSSI_to_return[bssi].append(got_bssi_temp[bssi][1])
        print "Medicao "+str(i)+" de "+str(seconds*times)
    print BSSI_to_return
    return BSSI_to_return

if __name__ == ‘__main__‘:

    #print get_interface()
    import time
    test = get_BSSI()
    for i in range(0,10):
        time.sleep(0.5)
        oldTest = test
        test = get_BSSI()
        print "Teste: "+str(i)
        if oldTest == test:
            print "IGUAL"
        else:
            print "DIFERENTE"
        for item in test.items():
            print item
    print "End"

本文标题 :使用Python我怎样才能检索Windows附近的无线局域网网络的信号强度?
本文地址 :CodeGo.net/156320/

时间: 2024-10-29 00:50:08

使用Python检索Windows附近的无线局域网网络的信号强度RSSI的相关文章

笔记本连接无线局域网的设置

1.先在XP系统桌面上,一次单击[开始-设置-控制面板]命令,打开控制面板窗口,在其中双击网络图标,打开[网络连接]界面. 2.在这个界面中,用鼠标右键单击[无线网络连接]图标,从随后打开的快捷菜单中,执行[属性]命令,这样系统就会自动显示[无线网络连接属性]设置对话框. 3.在这里,大家可以用鼠标选中[无线网络配置]标签,并在随后弹出的标签页面中,用鼠标选中[用Windows来配置我的无线网络配置]复选项,这样就能启用自动无线网络配置功能. 4.接着用鼠标单击这里的[高级]按钮,打开一个[高级

WLAN 无线网络 07 - 无线局域网通讯概述

无线局域网通讯概述. 有人喜欢将无线局域网的通讯比作有线局域网将一根连接电脑的网线插入一个802.3的网络端口, 这里我认为有相似之处,也有很大的不同. 首先, 我们看一下 无线局域网的通讯基本过程. 802.11 网络,不论怎么配置,都少不了以下几个过程:扫描.认证.关联和通讯数据交互. 扫描:这里分两种情况,主动扫描和被动扫描 被动扫描:客户端监听由接入点发出的beacon帧,通过其携带的信息来学习周围的网络环境 主动扫描:客户端主动发出探测帧(probe request),接入点接收到探测

无线局域网

无线局域网是目前最新,也是最为热门的一种局域网,特别是自Intel推出首款自带无线网络模块的迅驰笔记本处理器以来.无线局域网与传统的局域网主要不同之处就是传输介质不同,传统局域网都是通过有形的传输介质进行连接的,如同轴电缆.双绞线和光纤等,而无线局域网则是采用空气作为传输介质的.正因为它摆脱了有形传输介质的束缚,所以这种局域网的最大特点就是自由,只要在网络的覆盖范围内,可以在任何一个地方与服务器及其它工作站连接,而不需要重新铺设电缆.这一特点非常适合那些移动办公一簇,有时在机场.宾馆.酒店等(通

android通过无线局域网访问pc机上tomcat服务器的资源

============问题描述============ 最近在做一个android的项目,到了网络部分了,遇到的问题是怎样通过android的wifi,利用无线局域网访问pc机上tomcat搭载的服务器上的资源.项目是一个 基于移动平台的应用,需要从服务器上读取资源,自己在网上也找了很多相关了帖子看了,基本上说的方法差不多,都没有说到重点,都是复制粘贴的转来转去,希望有做过这样的成功案例的高手们教教我,给我详细的步骤来让我完成,谢谢!!! ============解决方案1==========

用python写windows服务

用python写windows服务(1) 以python2.5 为例需要软件 * python 2.5        * pywin32(与2.5 版本相匹配的) Service Control Manager (SCM) 服务管理器(SCM) 是windows NT的 一部分,所有服务必须通过SCM 注册,SCM负责启动,停止服务等. 当一个进程通过SCM注册后, 有如下特质: * 运行该进程的用户,未必是当前登录的用户.        * 该进程如果依赖其他服务,哪么该服务启动前,依赖服务回

从两部WIFI无线局域网IP网络电话机到企业电话系统的改造

起因很简单,也很悲剧.工厂大门门卫那里没有电话线,也没网线,成了一个没有信息的"孤岛". 没网线也就罢了,因为有WIFI.全厂区都覆盖了WIFI无线局域网. 电话可不行.尤其是前台和门卫有时要沟通.于是采购了两部WIFI IP电话机.前台一部,门卫一部.前台摘机,门卫电话就响了,拿起来就能通话.跟对讲机一样,还是双向的,免提着用,方便. 后来老板看到了,觉得挺好,也想弄一个,下回要叫秘书来给客人添茶水,按个电话机上的免提键,吩咐一声就行了,不用喊一嗓子,有派.     这次不让响铃了,

python在windows下UnicodeDecodeError的解决方法

之前在windows下使用python调用某些模块时都会报错,像这样: C:\Documents and Settings\Administrator>python -m CGIHTTPServer Traceback (most recent call last): File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_

无线局域网的3大问题和解决方法

无线局域网被认为是一种不可靠的网络,除了加强网络管理以外,更需要测试设备的构建.实施.维护和管理 尽管IT的寒冬还未渡过,但WLAN以其便利的安装.使用,高速的接入速度,可移动的接入方式赢得了众多公司.政府.个人以及电信运营商的青睐.但WLAN中,由于传送的数据是利用无线电波在空中辐射传播,无线电波可以穿透天花板.地板和墙壁,发射的数据可能到达预期之外的.安装在不同楼层.甚至是发射机所在的大楼之外的接收设备,数据安全也就成为最重要的问题. 问题一 容易侵入 无线局域网非常容易被发现,为了能够使用

无线局域网的另外4大问题和解决方法

无线局域网被认为是一种不可靠的网络,除了加强网络管理以外,更需要测试设备的构建.实施.维护和管理 尽管IT的寒冬还未渡过,但WLAN以其便利的安装.使用,高速的接入速度,可移动的接入方式赢得了众多公司.政府.个人以及电信运营商的青睐.但WLAN中,由于传送的数据是利用无线电波在空中辐射传播,无线电波可以穿透天花板.地板和墙壁,发射的数据可能到达预期之外的.安装在不同楼层.甚至是发射机所在的大楼之外的接收设备,数据安全也就成为最重要的问题. 上次我们已经说了前面的3个问题,现在我们再来说下还有其他