79 lines
1.6 KiB
C++
79 lines
1.6 KiB
C++
#include "ESP8266WiFi.h"
|
|
#define LED_PIN LED_BUILTIN
|
|
#define COLUMN_SEPARATOR "\t"
|
|
#define ROW_SEPARATOR "\n"
|
|
|
|
void setup() {
|
|
pinMode(LED_PIN, OUTPUT);
|
|
Serial.begin(115200);
|
|
WiFi.mode(WIFI_STA);
|
|
WiFi.disconnect();
|
|
|
|
Serial.printf(
|
|
"ssid%schannel%ssignal%sencryption%sbssid%s",
|
|
COLUMN_SEPARATOR,
|
|
COLUMN_SEPARATOR,
|
|
COLUMN_SEPARATOR,
|
|
COLUMN_SEPARATOR,
|
|
ROW_SEPARATOR
|
|
);
|
|
}
|
|
|
|
void loop() {
|
|
digitalWrite(LED_PIN, HIGH);
|
|
int count = WiFi.scanNetworks(false, true);
|
|
digitalWrite(LED_PIN, LOW);
|
|
|
|
String ssid;
|
|
uint8_t encryptionType;
|
|
int32_t rssi;
|
|
uint8_t* bssid;
|
|
int32_t channel;
|
|
bool isHidden;
|
|
String encryptionText;
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
WiFi.getNetworkInfo(i, ssid, encryptionType, rssi, bssid, channel, isHidden);
|
|
|
|
switch (encryptionType) {
|
|
case ENC_TYPE_WEP:
|
|
encryptionText = "WEP";
|
|
break;
|
|
case ENC_TYPE_TKIP:
|
|
encryptionText = "WPA1";
|
|
break;
|
|
case ENC_TYPE_CCMP:
|
|
encryptionText = "WPA2";
|
|
break;
|
|
case ENC_TYPE_NONE:
|
|
encryptionText = "NONE";
|
|
break;
|
|
case ENC_TYPE_AUTO:
|
|
encryptionText = "WPA1+2";
|
|
break;
|
|
// Encountered in the wild: 802.1X seems to set to 255
|
|
case 255:
|
|
encryptionText = "802.1X";
|
|
break;
|
|
default:
|
|
encryptionText = String(encryptionType);
|
|
}
|
|
|
|
Serial.printf(
|
|
"%s%s%d%s%d%s%s%s%s%s",
|
|
ssid.c_str(),
|
|
COLUMN_SEPARATOR,
|
|
channel,
|
|
COLUMN_SEPARATOR,
|
|
rssi,
|
|
COLUMN_SEPARATOR,
|
|
encryptionText.c_str(),
|
|
COLUMN_SEPARATOR,
|
|
WiFi.BSSIDstr(i).c_str(),
|
|
ROW_SEPARATOR
|
|
);
|
|
}
|
|
|
|
delay(1000);
|
|
}
|