· 7 years ago · Aug 27, 2018, 03:46 AM
1#include <SPI.h>
2#include <Ethernet.h>
3#include <Dns.h>
4#include <EthernetUdp.h>
5
6byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
7
8EthernetClient client;
9
10void setup() {
11 Serial.begin(9600);
12
13 if (Ethernet.begin(mac) == 0) {
14 Serial.println("Failed to configure Ethernet using DHCP");
15 while(true);
16 }
17
18 delay(1000);
19 Serial.println("connecting...");
20 DNSClient dnsClient;
21
22 // Router IP address
23 byte dnsIp[] = {192, 168, 11, 1};
24
25 dnsClient.begin(dnsIp);
26
27 // Regular DNS names work...
28 IPAddress ip1;
29 dnsClient.getHostByName("www.google.com", ip1);
30 Serial.print("www.google.com: ");
31 Serial.println(ip1);
32
33 // However local ones defined by my router do not (but they work fine everywhere else)...
34 IPAddress ip2;
35 dnsClient.getHostByName("Tycho.localnet", ip2);
36 Serial.print("Tycho.localnet: ");
37 Serial.println(ip2);
38}
39
40void loop() {
41
42}
43
44connecting...
45www.google.com: 74.125.227.84
46Tycho.localnet: 195.158.0.0
47
48$ nslookup www.google.com
49Server: 192.168.11.1
50Address: 192.168.11.1#53
51
52Non-authoritative answer:
53Name: www.google.com
54Address: 74.125.227.80
55Name: www.google.com
56Address: 74.125.227.84
57Name: www.google.com
58Address: 74.125.227.82
59Name: www.google.com
60Address: 74.125.227.83
61Name: www.google.com
62Address: 74.125.227.81
63
64$ nslookup Tycho.localnet
65Server: 192.168.11.1
66Address: 192.168.11.1#53
67
68Name: Tycho.localnet
69Address: 192.168.11.2
70
71while (*p &&
72 ( (*p == '.') || (*p >= '0') || (*p <= '9') ))
73
74while (*p &&
75 ( (*p == '.') || ((*p >= '0') && (*p <= '9')) ))