如何获取计算机可以通过Python查看的所有WLAN列表?

时间:2015-01-22 08:03:40

标签: python wlan

我尝试了以下内容:

#!/usr/bin/env python

import NetworkManager


def get_ssids():
    ssids = []
    for x in NetworkManager.Settings.ListConnections():
        conn = x.GetSettings()
        if '802-11-wireless' in conn and 'ssid' in conn['802-11-wireless']:
            ssids.append(conn['802-11-wireless']['ssid'])
            logging.info(conn)
    return ssids


def main():
    print("Found the following SSIDs:")
    for ssid in get_ssids():
        print("* %s" % ssid)


if __name__ == '__main__':
    main()

但是这显示了我所连接的所有网络的SSID,而不是我目前看到的网络的SSID。

1 个答案:

答案 0 :(得分:2)

这里的图书馆作者: - )

import NetworkManager

for dev in NetworkManager.NetworkManager.GetDevices():
    if dev.DeviceType != NetworkManager.NM_DEVICE_TYPE_WIFI:
        continue
    for ap in dev.SpecificDevice().GetAccessPoints():
        print ap.Ssid