#pip install pywifi
#pip install comtypes
import pywifi
from pywifi import const
import logging
import time
pywifi.set_loglevel(logging.INFO)
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
print(iface)
print(iface.name())
iface.scan()
time.sleep(5)
wifinets = iface.scan_results()
for wifinet in wifinets:
print(wifinet)
print(wifinet.bssid)
print(wifinet.ssid)
import pywifi
from pywifi import const
import logging
import time
pywifi.set_loglevel(logging.INFO)
def connect():
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
iface.disconnect()
profile = pywifi.Profile()
profile.ssid = 'testssid'
#profile.bssid = "ap bssid"
profile.auth=const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_WPA2PSK)
profile.cipher = const.CIPHER_TYPE_CCMP
profile.key = "passphrase"
iface.remove_all_network_profiles()
tmp_profile = iface.add_network_profile(profile)
iface.connect(tmp_profile)
time.sleep(10)
if iface.status() == const.IFACE_CONNECTED:
print("connect successfully")
else:
print("connect failed")
connect()