471,328 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,328 software developers and data experts.

GetHostByAddress

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 "-";
}
}
Jul 21 '05 #1
1 2385
If it is throwing a exception you can catch the exception and return '-'. If
your 'if' condition return statement returns this message may be you should
add additional if condition to check the length of return message or some
thing like that

"huzz" wrote:
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 "-";
}
}

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by ruggierorizzi | last post: by
1 post views Thread by Amy L. | last post: by
3 posts views Thread by RZ | last post: by
1 post views Thread by Jed | last post: by
3 posts views Thread by Jerome Lavalley, MCSE | last post: by
1 post views Thread by huzz | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.