mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-22 21:23:07 +03:00
42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
#include <ESP8266WiFi.h>
|
|
#include <DNSServer.h>
|
|
#include <ESP8266WebServer.h>
|
|
|
|
const byte DNS_PORT = 53;
|
|
IPAddress apIP(192, 168, 1, 1);
|
|
DNSServer dnsServer;
|
|
ESP8266WebServer webServer(80);
|
|
|
|
void setup() {
|
|
WiFi.mode(WIFI_AP);
|
|
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
|
|
WiFi.softAP("DNSServer example");
|
|
|
|
// modify TTL associated with the domain name (in seconds)
|
|
// default is 60 seconds
|
|
dnsServer.setTTL(300);
|
|
// set which return code will be used for all other domains (e.g. sending
|
|
// ServerFailure instead of NonExistentDomain will reduce number of queries
|
|
// sent by clients)
|
|
// default is DNSReplyCode::NonExistentDomain
|
|
dnsServer.setErrorReplyCode(DNSReplyCode::ServerFailure);
|
|
|
|
// start DNS server for a specific domain name
|
|
dnsServer.start(DNS_PORT, "www.example.com", apIP);
|
|
|
|
// simple HTTP server to see that DNS server is working
|
|
webServer.onNotFound([]() {
|
|
String message = "Hello World!\n\n";
|
|
message += "URI: ";
|
|
message += webServer.uri();
|
|
|
|
webServer.send(200, "text/plain", message);
|
|
});
|
|
webServer.begin();
|
|
}
|
|
|
|
void loop() {
|
|
dnsServer.processNextRequest();
|
|
webServer.handleClient();
|
|
}
|