#--------------------------------------------------
# Module importieren
import network
import time

#--------------------------------------------------
# setup

# WiFi auf ESP32 starten
wlan = network.WLAN(network.STA_IF)
wlan.active(True)

#--------------------------------------------------
# loop
while True:
    # Scannt nach Netzwerken
    print("Scanne nach WLAN-Netzwerken...")
    networks = wlan.scan() 

    # Info-Ausgabe in der Konsole
    print("\nGefundene Netzwerke:")
    print("-----------------------------------------------------------------------")
    print("{:<30} {:<6} {:<6} {}".format("SSID", "Kanal", "RSSI", "Verschlüsselung"))
    print("-----------------------------------------------------------------------")

    for ssid, bssid, channel, rssi, authmode, hidden in networks:
        encryption = [
            "Offen",
            "WEP",
            "WPA-PSK",
            "WPA2-PSK",
            "WPA/WPA2-PSK"
        ][authmode] if authmode < 5 else "Unbekannt"

        print("{:<30} {:<6} {:<6} {}".format(ssid.decode('utf-8'), channel, rssi, encryption))

    # 5 Sekunden Pause
    print("\nWarte 5 Sekunden vor dem nächsten Scan...\n")
    time.sleep(5)