473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 2561
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ruggierorizzi | last post by:
Hi everyone, i would like to know if there is a difference between gethostbyaddress method and $_SERVER. furthermore i hve a little problem using ip address resolution. Some ip address...
1
by: Rushikesh Joshi | last post by:
Hi Friends I am having some query. On a server two site hosted 1) magnamags.com 2) stardustindia.com Now when I am resolving the IP address for this both sites. I am getting...
1
by: Amy L. | last post by:
When I make the following call: IPHostEntry hostInfo = Dns.GetHostByAddress( hostIPAddress ) ; If the PTR (i.e. the IP address to name resolution) does not exist my program will start making...
3
by: RZ | last post by:
Hi Folks, I wrote an app to scan our Packet Filter logs for certain IPs. It uses GetHostByAddress(). I used multi-threading to get around the 2 second hang. The remaining problem is that...
5
by: Sven | last post by:
Hi! I have a problem with System.Net.Dns.GetHostByAddress(ls_Request.UserHostAddress()).HostName Usually the call GetHostByAddress returns the correct hostname of the client, but sometimes...
1
by: Jed | last post by:
I have a class for logging information about user activity on a web site, but it suddenly became really slow. I was wondering what factors may have caused the slow down. Initially, I used the...
3
by: Jerome Lavalley, MCSE | last post by:
I have an application that does a reverse lookup using System.net.dns.gethostbyaddress, however I am encountering some problems. If the application resolves the address of another machine it...
1
by: huzz | last post by:
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...
3
by: Steve Richter | last post by:
I am using Dns.GetHostByAddress and Dns.Resolve to successfully resolve and IP address to an IPEndPoint. IPEndPoint ep = null; IPAddress ipAddr = IPAddress.Parse(m_sRemoteHost); ep = new...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.