Question

I want to resolve a IP address but I don't get the desired result.

I want to retreive the real web name something like this: http://www.google.com

But what I get is: mad01s14-in-f6.1e100.net

Public Function IP_To_HostName(ByVal IP As String) As String
    Return system.net.Dns.GetHostEntry(IP).HostName.ToString
End Function

   MsgBox(IP_To_HostName("173.194.41.6")) ' One of the Google addresses

I don't know much about web protocols and this, where I'm failing?

PS: Notice I don't want to use the obsolete methods!

UPDATE:

Tried this to get "www.google.com" as string but seems that the Ip address don't have any alias... (Length of Aliases is 0, I can't understand why)

 For Each a In System.Net.Dns.GetHostEntry("173.194.41.6").Aliases
        MsgBox(a) ' Is empty
 Next
Was it helpful?

Solution

I tested this code with Google's DNS Server 8.8.8.8 and it returns "google-public-dns-a.google.com" which is correct.

Public Function UseIPGetHost(ByRef IPAddr As String) As String
    Dim hostname As System.Net.IPHostEntry

    hostname = System.Net.Dns.GetHostEntry(IPAddr)
    Return hostname.HostName
End Function

Maybe you should just use your code, but make it multiple lines and use variables so that it is easier to read for you and you can see the process. Hope this helps you!

OTHER TIPS

There is no simple solution of your problem. If you ask DNS server for host entry it gives you the name stored there. Usually there is only one record for one IP address( Reverse DNS lookup). On the other hand the number of forward records pointing to one IP address is not limited and in case of web servers there can be hundreds of webs (aliases) running on 1 IP. Forward records of those aliases can be(and usually are) scatered on many DNS servers.

To solve your problem you would need to search all DNS servers on Internet to find which aliases are pointing to the desired IP and finally to choose the desired one.

Edit

You can try some networ tools e.g. http://network-tools.com/ do discover what can be found about an IP address. If you find some parameters are usable for you its possible to discover them from code later on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top