我尝试了以下内容:
#!/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。
答案 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