[Submission] DNS lookup (alternate getHostByName)

I couldn’t get the inbuilt DNS lookup to work when using TCP Client on a very slow internet connection, so i ported the arduino ethernet library.

May also be useful if you want to specify your own DNS server. Ive included a very simple example code, change the hostname to what you want to look up and it will tell you the IP address.

Its available here. https://github.com/Hootie81/DNSClient

Big thanks to @bko @AndyW @wgbartley for your help and info porting this

5 Likes

@Hootie81,

Do you mind adding this as a library, so that others (i.e. me - haha) can get easy access to it from the Spark IDE? Thanks for contributing it, and look forward to trying it out!

(I’d add it myself, but I’m not sure it’s good form to add someone else’s library to the IDE… )

Cheers,
L3

2 Likes

Yep ill give it a go… just need to work out how :slight_smile:

Edit… Its in the wild, its called DNSCLIENT

1 Like

Awesome! Thanks so much. Cheers, L3

@Hootie81,

I got an error on compile because it couldn’t find myUDP. I hate to nag, but can you also upload myUDP.h and myUDP.cpp? Thanks,

L3

Sorry about that, got a bit excited when tidying up the repo and removing extra folders etc. the myUDP.h is just a header file that overloads the built-in functions, it in a way grabs all the little bits and sends them as one datagram instead of lots of little ones :slight_smile: so there is no matching cpp.

Ive also added loads of comments so you can easily see what can be removed from the example, and what the returned error codes mean, any issues let me know

Thanks! Much, much appreciated. Cheers, L3

Let me know if it works, i haven’t got a core available to test at the moment.

Even if its just a little thing its easy enough for me to fix.

@Hootie81,

Can you change “#include DNSClient.h” to “#include dnsclient.h” at the top of dnsclient.cpp file? Thx,

L3

Done, also fixed in the example

1 Like

AWESOME!!! It worked great. I can’t thank you enough, @Hootie81. You da man!

Cheers,
L3

2 Likes

Did you test the same core on a faster network? I have 6 cores using the same internet connection and only two of them are having problems with DNS. I was curious if you tested a problem core (on slow internet) with a faster internet and the problem went away?

I have unfortunately had all 3 of the issues that lead to needing the library… The corrupt DNS of 76.83.0.0 on one core. A router that doesn’t have a working DNS server and lastly a slow connection that takes more than 1 second to do a lookup the library fixes all 3.

The bad router was fixed by putting another router with manual DNS setup and the slow Internet I couldn’t do anything about but the cores work normal at home

The DHCP server on my wifi router assigns DNS servers from my ISP. What should I do to get the domain lookup search for .local hostnames first in the LAN?

I’ve tried this on a raspberrypi.local hostname, which is basically a RPi connected to the same WLAN. The .local hostname is ping-able from terminal, but I get a -5 error code when trying to connect from my Spark Core.

In this case, what DNS server should I provide for dnsServerIP()?

You can point your core to your router gateway ip

1 Like