Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get host name from IP address

Tags:

c#

I have managed to get the connected clients IP with the code below but can't seem to get the hostname.

Globals.connectedIPAddress = "" + IPAddress.Parse(((
    IPEndPoint)_client.Client.RemoteEndPoint).Address.ToString());
like image 393
arbme Avatar asked Jul 15 '10 14:07

arbme


People also ask

How do I find the hostname?

Click Start, right-click Computer, and then click Properties. The computer name appears under Computer name, domain, and workgroup settings.

How do I find the hostname of an IP address in Windows?

First, click on your Start Menu and type cmd in the search box and press enter. A black and white window will open where you will type ipconfig /all and press enter. There is a space between the command ipconfig and the switch of /all. Your ip address will be the IPv4 address.

Is the host name the IP address?

Host names are sometimes called domain names. Host names are mapped to IP addresses, but a host name and an IP address do not have a one-to-one relationship. A host name is used when a web client makes an HTTP request to a host.

How do I find my hostname in cmd?

Locating Your Computer's Hostname on a PC (Windows 10)In the window the window that appears on the bottom-left hand corner of your screen, type in cmd and click OK. The command prompt window will appear. In this window, type hostname and press Enter. The name of your computer will be displayed.


1 Answers

Well, not every IP address has a name. However, given the IPAddress you can use Dns.GetHostEntry to try to resolve it. Also note that if it's being a NAT router, you'll be getting the router's IP address rather than their actual machine.

And just to address the point in the comments, I agree that there's no point in ToString/Parse/ToString:

IPAddress address = ((IPEndPoint)_client.Client.RemoteEndPoint).Address;
Globals.connectedIPAddress = address.ToString();
like image 103
Jon Skeet Avatar answered Oct 11 '22 15:10

Jon Skeet