Skip to content

Instantly share code, notes, and snippets.

@VNovytskyi
Created June 9, 2022 10:14
Show Gist options
  • Save VNovytskyi/62c4649328578a7fe77372e55f21a8b5 to your computer and use it in GitHub Desktop.
Save VNovytskyi/62c4649328578a7fe77372e55f21a8b5 to your computer and use it in GitHub Desktop.
ESP32 DNS example: hostname => IP
#include <WiFi.h>
#define WIFI_SSID ""
#define WIFI_PASS ""
#define DNS_TEST_DOMAIN "google.com"
void setup() {
Serial.begin(115200);
Serial.printf("\n\nStart initialization...\n");
Serial.printf("Begin connecting to %s...\n", WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while(WiFi.status() != WL_CONNECTED);
IPAddress ip = WiFi.localIP();
Serial.printf("Conected to %s. IP address: %d.%d.%d.%d\n", WIFI_SSID, ip[0], ip[1], ip[2], ip[3]);
IPAddress srv((uint32_t)0);
if(!WiFiGenericClass::hostByName(DNS_TEST_DOMAIN, srv)){
Serial.printf("Failt to resolve %s\n", DNS_TEST_DOMAIN);
}
Serial.printf("%s => %d.%d.%d.%d\n", DNS_TEST_DOMAIN, srv[0], srv[1], srv[2], srv[3]);
}
void loop() {
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment