tags:

views:

525

answers:

6

Hi,

I wanted to show the users Name Address (see: www.ipchicken.com), but the only thing I can find is the IP Address. I tried a reverse lookup, but didn't work either:

IPAddress ip = IPAddress.Parse(this.lblIp.Text);
string hostName = Dns.GetHostByAddress(ip).HostName;
this.lblHost.Text = hostName;

But HostName is the same as the IP address.

Who know's what I need to do?

Thanks. Gab.

A: 

Not all IP addresses need to have hostnames. I think that's what is happening in your case. Try it ouy with more well-known IP/hostname pairs eg:

Name: google.com Address: 72.14.207.99

Name: google.com Address: 64.233.187.99

Name: google.com Address: 64.233.167.99

...I might just be wrong

saniul
A: 

A lot of users have the same shared IP address, so you will not be able to find their hostnames. And a lot of users won't necessarily have DNS records in public DNS for the IPs they are coming from as well.

Vaibhav
+2  A: 

Edit of my previous answer. Try (in vb.net):

    Dim sTmp As String
    Dim ip As IPHostEntry

    sTmp = MaskedTextBox1.Text
    Dim ipAddr As IPAddress = IPAddress.Parse(sTmp)
    ip = Dns.GetHostEntry(ipAddr)
    MaskedTextBox2.Text = ip.HostName

Dns.resolve appears to be obsolete in later versions of .Net. As stated here before I believe the issue is caused by your IP address not having a fixed name or by it having multiple names. The example above works with Google addresses, but not with an address we use that has a couple of names associated with it.

seanyboy
+2  A: 

You need the Dns.Resolve() method from System.Net

See this article

Adam Haile
A: 

Also remember that reverse lookup won't allways give the same address as the one used in forward DNS lookup.

For example for google.com I get ip 64.233.167.99
but reverse dns lookup for that IP returns py-in-f99.google.com

Michał Piaskowski
+2  A: 

Stupid me... The code is posted was 100% valid and working... But 10 lines lower I replaced the this.lblHost.Text with another value, which happened to be the ip address.

Sorry.

Gabriël