Ermittelt den host anhand einer IP-Adresse.
Host.IsNull() ist eine extension method also schreibt Host == null...
/// <summary>
/// Resolves the host name from the given IP address.
/// </summary>
/// <param name="IPAddress">The ip address for getting the host name.</param>
/// <returns>The host name if exists else "no entry"</returns>
public static String GetHostNameByIp(String IPAddress)
{
System.Net.IPHostEntry Host = null;
try
{
System.Net.IPAddress IP;
if (System.Net.IPAddress.TryParse(IPAddress, out IP))
Host = System.Net.Dns.GetHostEntry(IP);
}
catch
{
}
return Host.IsNull() ? "No entry" : Host.HostName;
}
Kommentare zum Snippet