473,563 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GetHostByAddres s

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(st ring IPAddress)
{
IPHostEntry HostInfo = Dns.GetHostByAd dress(IPAddress );
if(HostInfo.Hos tName.ToString( )!="")
{
string[] arrHostname = HostInfo.HostNa me.Split('.');
return arrHostname[0].ToLower();
}
else
{
return "-";
}
}
Jul 21 '05 #1
1 2589
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(st ring IPAddress)
{
IPHostEntry HostInfo = Dns.GetHostByAd dress(IPAddress );
if(HostInfo.Hos tName.ToString( )!="")
{
string[] arrHostname = HostInfo.HostNa me.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
5200
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 are resolved other not. Why?
1
369
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 202.71.136.211 (using GetHostByName).
1
471
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 Netbios calls (Name query to the remote host). The netbios lookup is very undesired. Is there a way to not perform the netbios query if the PTR...
3
4018
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 GetHostByAddress() also attempts to resolve the machine name via NetBIOS. After running the application, the blocked packets to port 137 from our own...
5
2248
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 I get a hostname like _CERDR1342B88E. Why? The clients are running under Windows CE.NET 4.1...
1
2598
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 following code: ul.HostName = context.Request.UserHostName; Since the UserHostName is not always resolved, I opted for the following more...
3
1673
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 works fine, but when resolving its own address, I get incorrect results. SERVERA has 2 IP addresses (IPA1, IPA2). Each IP address has one DNS entry...
1
272
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 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 ...
3
16590
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 IPEndPoint(Dns.GetHostByAddress(ipAddr).AddressList, m_iRemotePort); // ep = new IPEndPoint(Dns.GetHostEntry(ipAddr).AddressList, m_iRemotePort); // ep...
0
7665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.