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());
Click Start, right-click Computer, and then click Properties. The computer name appears under Computer name, domain, and workgroup settings.
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.
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.
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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With