473,408 Members | 1,623 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,408 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 2565
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.