I'm trying to list the names of the computer names currently online on a network. I've only managed to get the get active IPs but I cannot get the computer name of these IPs. Any ideas ?
Querying DNS Click the Windows Start button, then "All Programs" and "Accessories." Right-click on "Command Prompt" and choose "Run as Administrator." Type "nslookup %ipaddress%" in the black box that appears on the screen, substituting %ipaddress% with the IP address for which you want to find the hostname.
Here is a simple method to find hostname and IP address using C program. gethostname() : The gethostname function retrieves the standard host name for the local computer. gethostbyname() : The gethostbyname function retrieves host information corresponding to a host name from a host database.
You can use Dns.GetHostEntry to try to resolve the name, because not every IP has a name.
using System.Net;
...
public string GetHostName(string ipAddress)
{
try
{
IPHostEntry entry = Dns.GetHostEntry(ipAddress);
if (entry != null)
{
return entry.HostName;
}
}
catch (SocketException ex)
{
//unknown host or
//not every IP has a name
//log exception (manage it)
}
return null;
}
If you've already got a list of ip adresses, you can find the name with:
System.Net.Dns.GetHostEntry("youripaddress").HostName;
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