Ohad Schneider Ohad Schneider - 2 years ago 125
C# Question

External DNS lookup web service (NSLOOKUP / DiG)

Several sites offer hostname to IP conversions, or in their wording:

Query a DNS domain nameserver to
lookup and find IP address information
of computers in the internet. Convert
a host or domain name into an IP

However, I haven't been able to find any free webservices offering this functionality.
I've stumbled upon this Chinese webservice but it doesn't seem to do what I want.

Anyone know of a free one ?

Clarification of exactly what I want to be able to do:
I want an free, external web service (on a computer different than mine, somewhere in the internet) providing a simple nslookup method with a signature such as:

IPAddress[] GetIpAddress(string hostName)

Where the result is equivalent to what I would get here:

Kev Kev
Answer Source

You don't say exactly what you want to be able to do. However there are a one or two dig type C# implementations such as:

DNS.NET Resolver (C#) - CodeProject

I've used this one in the past and it works pretty well.


You already have this available. There's plenty of free DNS services such as Google or OpenDNS you can use as nameservers.

Using .NET's built in capabilities you can use the System.Net namespace and the Dns class. There's a couple of static methods you could use:

IPHostEntry GetHostEntry(string hostNameOrAddress)

IPAddress[] GetHostAddresses(string hostNameOrAddress)

The above methods will query the DNS servers as specified in the computer's own network settings.

If you want to specify your own resolver then use the Dig tool I mentioned above. The output goes straight to the console but you could modify to parse the results into return values.

Adding a reference to the project I was able to do this:

Dig dig = new Dig();
dig.DnsResolver = new Resolver("");

The results returned look like:

; <<>> Dig.Net 0.0.1 <<>> @ A stackoverflow.com.net
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53737
;; flags:  qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 0

;stackoverflow.com.net.                 IN      A

stackoverflow.com.net.          1800    IN      A
stackoverflow.com.net.          3600    IN      A
stackoverflow.com.net.          3600    IN      A
stackoverflow.com.net.          1800    IN      A
stackoverflow.com.net.          43200   IN      A
stackoverflow.com.net.          43200   IN      A

;; Query time: 216 msec
;; WHEN: Mon Oct 04 17:11:48 2010
;; MSG SIZE rcvd: 135

You don't need a third party service to be able to do this.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download