.netasp.net

Getting the Remote Name Address (not IP)


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?


Solution

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