Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the Remote Name Address (not IP)

Tags:

.net

asp.net

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.

like image 441
Gabriël Avatar asked Mar 02 '23 08:03

Gabriël


1 Answers

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.

like image 196
seanyboy Avatar answered Mar 05 '23 18:03

seanyboy