Chat here about code rewrites, mods, etc... with respect to the github project https://github.com/esp8266/Arduino

Moderator: igrr

User avatar
By relo
#31156 Is it possible to retrieve the address of the DNS server which has beeen assigned by DHCP?
User avatar
By martinayotte
#31258 You can use the SDK API itself :

Code: Select allextern "C" {
#include "user_interface.h"
#include "lwip/err.h"
#include "lwip/dns.h"
}

void showDNS() {
  ip_addr_t dns_ip = dns_getserver(0);
  IPAddress dns = IPAddress(dns_ip.addr);
  String str = String("DNS IP Addr: ");
  str += dns.toString(); 
  Serial.println(str);
}
User avatar
By relo
#31354 Thanx, it works perfectly!

I would suggest to include this into the ESP8266WiFi library for good programming practice,
because we can set the dns with
Code: Select allvoid config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns);

and can retrieve all
Code: Select allIPAddress localIP();
IPAddress subnetMask();
IPAddress gatewayIP();

but not the dns IP yet. What's simply missing is this code in ESP8266WiFi.h:
Code: Select all/*
 * Get the dns server ip address.
 *
 * return: dns server ip address value
 */
IPAddress dnsIP();

And this in ESP8266WiFi.cpp:
Code: Select allIPAddress ESP8266WiFiClass::dnsIP()
{
     ip_addr_t dns_ip = dns_getserver(0);
     return IPAddress(dns_ip.addr);
}


What do you think?
User avatar
By martinayotte
#31367 Yes ! of course !
I was thinking the same when trying the piece of code before sending my post.
I will do, it only question of time is always the missing ingredient ... ;)