开发者

Is it possible to scan for Wi-Fi using Python?

开发者 https://www.devze.com 2023-01-08 18:22 出处:网络
I am interested in writing a script in Python that is able to scan and sh开发者_高级运维ow a list of nearby Wi-Fi networks. How could one do this? If possible.

I am interested in writing a script in Python that is able to scan and sh开发者_高级运维ow a list of nearby Wi-Fi networks. How could one do this? If possible.

Thanks.

Jake.


Yes, it is possible. As far as the how is concerned, this might help you get started.

Additionally you can use the pywifi package to scan for all wireless devices in your area.

example:

 import pywifi
 import time

 wifi = pywifi.PyWiFi()
 iface = wifi.interfaces()[0]
 iface.scan()
 time.sleep(0.5)
 results = iface.scan_results()


 for i in results:
     bssid = i.bssid
     ssid  = i.ssid
     print(f"{bssid}: {ssid}")


It is actually possible using subprocess module

import subprocess
networks = subprocess.check_output(['netsh', 'wlan', 'show', 'network'])
networks = networks.decode('ascii')
networks = networks.replace('\r', '')
ssid = networks.split('\n')
ssid = ssid[4:]
ssids = []
x = 0

while x < len(ssid):
    if x % 5 == 0:
        ssids.append(ssid[x])
    x += 1
print(ssids)  
0

精彩评论

暂无评论...
验证码 换一张
取 消