2

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 address.

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: http://www.kloth.net/services/nslookup.php

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Ohad Schneider
  • 36,600
  • 15
  • 168
  • 198

1 Answers1

4

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.

Update:

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("8.8.8.8");
dig.DigIt("stackoverflow.com");

The results returned look like:

; <<>> Dig.Net 0.0.1 <<>> @8.8.8.8 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

;; QUESTION SECTION:
;stackoverflow.com.net.                 IN      A

;; ANSWER SECTION:
stackoverflow.com.net.          1800    IN      A       74.207.240.60
stackoverflow.com.net.          3600    IN      A       203.169.164.119
stackoverflow.com.net.          3600    IN      A       97.107.142.101
stackoverflow.com.net.          1800    IN      A       69.164.199.155
stackoverflow.com.net.          43200   IN      A       74.207.231.120
stackoverflow.com.net.          43200   IN      A       109.74.195.184

;; Query time: 216 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; 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.

Kev
  • 118,037
  • 53
  • 300
  • 385
  • Hi, using your code I get: ; <<>> Dig.Net 1.0.0.1 <<>> @8.8.8.8 A stackoverflow.com ;; global options: printcmd ;; Timeout Error – Ohad Schneider Oct 05 '10 at 09:03
  • @ohadsc - it's possible Google's name servers are blocked where you are? Try it with OpenDNS (208.67.222.222 or 208.67.220.220) or your own ISP's DNS servers. – Kev Oct 05 '10 at 09:38
  • Yes, it appears they are. I've also tried some resolvers from www.dnsserverlist.org and they are all blocked. Only my own network's resolver works, but like I said I need an external one. Back to square one ? – Ohad Schneider Oct 05 '10 at 09:54
  • @ohadsc - That's a shame, I take it there's no way to persuade your network admins to permit access to these external DNS servers (for the benefit of the business is always a good excuse). – Kev Oct 05 '10 at 10:00
  • LOL, you know network admins :) So I take it they are blocking the DNS resolution port ? Is there some way to relay it to port 80 or something like that ? – Ohad Schneider Oct 05 '10 at 10:02
  • @ohadsc - yeah looks like they're restricting the DNS well known port. You could buy some cheap $5/month ASP.NET hosting and create/deploy a simple web service? Or you could have a look at Tor, your might be able to tunnel DNS queries via that. That said I'd be careful, if you try and circumvent your employers security measures then you might find yourself flipping burgers for a career :). – Kev Oct 05 '10 at 10:39
  • Thanks, I'll try the web service route and mark your answer once I succeed – Ohad Schneider Oct 05 '10 at 14:34
  • @ohadsc - excellent! Did you go the external web service route? – Kev Oct 10 '10 at 13:18
  • Yep! One method that simply returns System.Net.Dns.GetHostAddresses(hostname).Select(ip => ip.ToString()).ToArray() – Ohad Schneider Oct 10 '10 at 14:47