Created
June 9, 2022 13:35
-
-
Save VNovytskyi/c61e86d153dcf04eaf81345b56da56a9 to your computer and use it in GitHub Desktop.
AVR Ethernet DNS example: hostname => IP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <Dns.h> | |
#include <Ethernet.h> | |
uint8_t mac[6]; | |
void setup() { | |
Serial.begin(115200); | |
Serial.println(F("System initialization start...")); | |
Ethernet.init(10); | |
mac[0] = 0xDE; | |
mac[1] = 0xAD; | |
mac[2] = 0xBE; | |
mac[3] = 0xEF; | |
mac[4] = 0xFE; | |
mac[5] = 0xED; | |
Ethernet.begin(mac); | |
if (Ethernet.hardwareStatus() == EthernetNoHardware) { | |
Serial.println(F("Ethernet shield was not found. Sorry, can't run without hardware. :(\n")); | |
return; | |
} | |
Serial.println(F("System initialization done")); | |
Serial.println("Start DNS request..."); | |
DNSClient dns; | |
IPAddress ip; | |
dns.begin(Ethernet.dnsServerIP()); | |
if(dns.getHostByName("google.com", ip) == 1) { | |
Serial.print(F("IP: ")); | |
Serial.println(ip); | |
} else { | |
Serial.print(F("dns lookup failed")); | |
} | |
Serial.println("End DNS request..."); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment