G
Guest
I wrote a method which takes an ip address and returns hostname as shown below.
It works fine.. only problem i have is when the passed ip address is not
found in the database the method throws this error message :
The requested name is valid and was found in the database, but it does not
have the correct associated data being resolved for
How can i prevent this error message and instead return "-" ?
Many Thanks.
public string IPToHostname(string IPAddress)
{
IPHostEntry HostInfo = Dns.GetHostByAddress(IPAddress);
if(HostInfo.HostName.ToString()!="")
{
string[] arrHostname = HostInfo.HostName.Split('.');
return arrHostname[0].ToLower();
}
else
{
return "-";
}
}
It works fine.. only problem i have is when the passed ip address is not
found in the database the method throws this error message :
The requested name is valid and was found in the database, but it does not
have the correct associated data being resolved for
How can i prevent this error message and instead return "-" ?
Many Thanks.
public string IPToHostname(string IPAddress)
{
IPHostEntry HostInfo = Dns.GetHostByAddress(IPAddress);
if(HostInfo.HostName.ToString()!="")
{
string[] arrHostname = HostInfo.HostName.Split('.');
return arrHostname[0].ToLower();
}
else
{
return "-";
}
}