473,729 Members | 2,309 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 2609
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
5219
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 record does not exist?
3
4029
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 IP are added
5
2258
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
2634
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 effective code: IPAddress hostIPAddress = IPAddress.Parse(context.Request.UserHostAddress);
3
1682
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 (HOSTA1, HOSTA2) SERVERB has 2 IP addresses (IPB1, IPB2). 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 How can i prevent this error message and instead return "-" ? Many Thanks.
3
16605
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 = new IPEndPoint(Dns.Resolve(m_sRemoteHost).AddressList,
0
8917
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9200
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6022
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.