Getting the remote name address (not IP)

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

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 knows what I need to do?

Thanks. Gab

+4
source share
6 answers

Edit my previous answer. Try it (at 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 seems to be deprecated in later versions of .Net. As stated above, I believe the problem is that your IP address does not have a fixed name or has multiple names. The example above works with Google addresses, but not with the address we use, which has a couple of names associated with it.

+3
source

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

See article

+2
source

Stupid for me ... The code is 100% valid and works ... But 10 lines below I replaced this.lblHost.Text with another value, which turned out to be an IP address.

Unfortunately.

+2
source

Also remember that reverse lookups will not always indicate the same address as in direct DNS lookup mode.


For example, for google.com I get ip 64.233.167.99
but a reverse dns search for this IP returns py -in-f99.google.com

+1
source

Not all IP addresses must have host names. I think what happens in your case. Try using the more famous IP / hostname pairs, for example:

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'm just wrong

0
source

Many users have the same shared IP address, so you cannot find their hostnames. And many users will not necessarily have DNS records in the public DNS for the IP addresses from which they come.

0
source

Source: https://habr.com/ru/post/1276379/


All Articles