![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Dns.GetHostEntry not working the same as Dns.Resolve or Dns.GetHos I am trying to get the DNS name of an arbitrary IP address on the network. If I use GetHostEntry as the documentation suggests I only get the name of the machine I am running the code on. All other IP’s returns the IP in the HostName property of the IPHostEntry object returned by GetHostEntry. If I use Dns.GetHostByAddress or Dns.Resolve I get the name, but these are marked as obsolete. What is the correct way to get this information in .Net 2.0? |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Dns.GetHostEntry not working the same as Dns.Resolve or Dns.GetHos Hello QSIDeveloper, As far as I know, Dns.GetHostEntry returns IP address as the HostName when no DNS servers respond to the reverse DNS query. For example, when all DNS servers are unreachable. Accompanied with this, the call of GetHostByAddress will throw a SocketException with message "The requested name is valid, but no data of the requested type was found". However, Dns.GetHostByAddress seems working fine on your side. Please give me some time. I will look for other reasons for the abnormal behavior of GetHostEntry. For your second question "What is the correct way to get this information in .Net 2.0": System.Net.Dns.GetHostByAddress is for .Net 1.1 or prior. From .NET 2.0, we use Dns.GetHostEntry. Regards, Jialiang Ge (jialge@xxxxxx, remove 'online.') Microsoft Online Community Support Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@xxxxxx. ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/en-us/subs...#notifications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://support.microsoft.com/select/...tance&ln=en-us. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Dns.GetHostEntry not working the same as Dns.Resolve or Dns.GetHos Hello QSIDeveloper, Sorry for my delayed response. I was trying to reproduce the symptom in my lab and look into the source code of Dns. Code list 1 is the source of the obsolete function "GetHostByAddress", and Code list 2 is for GetHostEntry: Code list 1 [Obsolete("GetHostByAddress is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202")] public static IPHostEntry GetHostByAddress(string address) { if(Logging.On)Logging.Enter(Logging.Sockets, "DNS", "GetHostByAddress", address); // // demand Unrestricted DnsPermission for this call // s_DnsPermission.Demand(); if (address == null) { throw new ArgumentNullException("address"); } GlobalLog.Print("Dns.GetHostByAddress: " + address); IPHostEntry ipHostEntry = InternalGetHostByAddress(IPAddress.Parse(address), false, true); if(Logging.On)Logging.Exit(Logging.Sockets, "DNS", "GetHostByAddress", ipHostEntry); return ipHostEntry; } // GetHostByAddress Code list 2 public static IPHostEntry GetHostEntry(string hostNameOrAddress) { if(Logging.On)Logging.Enter(Logging.Sockets, "DNS", "GetHostEntry", hostNameOrAddress); // // demand Unrestricted DnsPermission for this call // s_DnsPermission.Demand(); if (hostNameOrAddress == null) { throw new ArgumentNullException("hostNameOrAddress"); } // See if it's an IP Address. IPAddress address; IPHostEntry ipHostEntry; if (TryParseAsIP(hostNameOrAddress, out address)) { if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)) { throw new ArgumentException(SR.GetString(SR.net_invalid_ip_addr), "hostNameOrAddress"); } ipHostEntry = InternalGetHostByAddress(address, true, false); } else { ipHostEntry = InternalGetHostByName(hostNameOrAddress, true); } if (Logging.On) Logging.Exit(Logging.Sockets, "DNS", "GetHostEntry", ipHostEntry); return ipHostEntry; } By comparing the two, I see the difference is at the call of InternalGetHostByAddress. Code list 1: InternalGetHostByAddress(IPAddress.Parse(address), false, true); Code list 2: InternalGetHostByAddress(address, true, false); The declaration of InternalGetHostByAddress is: internal static IPHostEntry InternalGetHostByAddress(IPAddress address, bool includeIPv6, bool throwOnFailure) QSIDeveloper, are you using IPV6 on your side? If we gave a IPV6 address, the code path in InternalGetHostByAddress is different when the includeIPv6 param equals true and false. (I do not paste the code of InternalGetHostByAddress here, but you can see its code with http://blogs.msdn.com/sburke/archive...urce-code.aspx) IPv6 requires the use of getaddrinfo() rather than the traditional IPv4 gethostbyaddr() / gethostbyname(). getaddrinfo() is also protocol independant in that it will also resolve IPv4 names / addresses. As a result, it is the preferred resolution mechanism on platforms that support it (Windows 5.1+). In other words, if your environment is Window NT4 or 2000 where getaddrinfo() is unsupported, IPv6 resolution does not work. QSIDeveloper, would you please check the OS version? If IPv6 is disabled, we could detect IPv6 addresses and throw an unsupported platform exception. My additional suggestions that my help you trouble-shoot the issue: 1. Debug into the .NET Dsn source code according to the article http://blogs.msdn.com/sburke/archive...urce-code.aspx, and step through the code path of GetHostEntry. 2. looking at what the DNS interaction is using netmon. http://www.microsoft.com/downloads/d...displaylang=en Hope it helps Regards, Jialiang Ge Microsoft Online Community Support ================================================= Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@xxxxxx. This posting is provided "AS IS" with no warranties, and confers no rights. ============================================= ""Jialiang Ge [MSFT]"" <jialge@xxxxxx> wrote in message news:iZLUTQr$IHA.4792@xxxxxx Quote: > Hello QSIDeveloper, > > As far as I know, Dns.GetHostEntry returns IP address as the HostName when > no DNS servers respond to the reverse DNS query. For example, when all DNS > servers are unreachable. Accompanied with this, the call of > GetHostByAddress will throw a SocketException with message "The requested > name is valid, but no data of the requested type was found". However, > Dns.GetHostByAddress seems working fine on your side. Please give me some > time. I will look for other reasons for the abnormal behavior of > GetHostEntry. > > For your second question "What is the correct way to get this information > in .Net 2.0": > System.Net.Dns.GetHostByAddress is for .Net 1.1 or prior. From .NET 2.0, > we > use Dns.GetHostEntry. > > Regards, > Jialiang Ge (jialge@xxxxxx, remove 'online.') > Microsoft Online Community Support > > Delighting our customers is our #1 priority. We welcome your comments and > suggestions about how we can improve the support we provide to you. Please > feel free to let my manager know what you think of the level of service > provided. You can send feedback directly to my manager at: > msdnmg@xxxxxx. > > ================================================== > Get notification to my posts through email? Please refer to > http://msdn.microsoft.com/en-us/subs...#notifications. > > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues > where an initial response from the community or a Microsoft Support > Engineer within 1 business day is acceptable. Please note that each follow > up response may take approximately 2 business days as the support > professional working with you may need further investigation to reach the > most efficient resolution. The offering is not appropriate for situations > that require urgent, real-time or phone-based interactions or complex > project analysis and dump analysis issues. Issues of this nature are best > handled working with a dedicated Microsoft Support Engineer by contacting > Microsoft Customer Support Services (CSS) at > http://support.microsoft.com/select/...tance&ln=en-us. > ================================================== > This posting is provided "AS IS" with no warranties, and confers no > rights. > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Dns.GetHostEntry not working the same as Dns.Resolve or Dns.Ge Thank you for you research. The IP is xxx.xxx.xxx.xxx, I believe that is IPv4 1.) What I think you are saying is System.Net.Dns.GetHostEntry("10.10.60.221"); should work. Is that correct? When I make that call I always get back the IP address in IPHostEntry.HostName except when I put the IP address of my PC, in that case I get the machine name of my PC. 2.) Do you have any Ideas why this would behave this way? 3.) If System.Net.Dns.Resolve and System.Net.Dns.GetHostByAddress are obsolete when will they stop working in the 2.0 framework? I will look into you suggestion of debugging into framework code but could you respond to the question above in the meantime? "Jialiang Ge [MSFT]" wrote: Quote: > Hello QSIDeveloper, > > Sorry for my delayed response. I was trying to reproduce the symptom in my > lab and look into the source code of Dns. Code list 1 is the source of the > obsolete function "GetHostByAddress", and Code list 2 is for GetHostEntry: > > Code list 1 > [Obsolete("GetHostByAddress is obsoleted for this type, please use > GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202")] > public static IPHostEntry GetHostByAddress(string address) { > if(Logging.On)Logging.Enter(Logging.Sockets, "DNS", > "GetHostByAddress", address); > // > // demand Unrestricted DnsPermission for this call > // > s_DnsPermission.Demand(); > > if (address == null) { > throw new ArgumentNullException("address"); > } > > GlobalLog.Print("Dns.GetHostByAddress: " + address); > > IPHostEntry ipHostEntry = > InternalGetHostByAddress(IPAddress.Parse(address), false, true); > if(Logging.On)Logging.Exit(Logging.Sockets, "DNS", > "GetHostByAddress", ipHostEntry); > return ipHostEntry; > } // GetHostByAddress > > Code list 2 > public static IPHostEntry GetHostEntry(string hostNameOrAddress) > { > if(Logging.On)Logging.Enter(Logging.Sockets, "DNS", > "GetHostEntry", hostNameOrAddress); > // > // demand Unrestricted DnsPermission for this call > // > s_DnsPermission.Demand(); > > if (hostNameOrAddress == null) { > throw new ArgumentNullException("hostNameOrAddress"); > } > > // See if it's an IP Address. > IPAddress address; > IPHostEntry ipHostEntry; > if (TryParseAsIP(hostNameOrAddress, out address)) > { > if (address.Equals(IPAddress.Any) || > address.Equals(IPAddress.IPv6Any)) > { > throw new > ArgumentException(SR.GetString(SR.net_invalid_ip_addr), > "hostNameOrAddress"); > } > > ipHostEntry = InternalGetHostByAddress(address, true, > false); > } > else > { > ipHostEntry = InternalGetHostByName(hostNameOrAddress, > true); > } > > if (Logging.On) Logging.Exit(Logging.Sockets, "DNS", > "GetHostEntry", ipHostEntry); > return ipHostEntry; > } > > By comparing the two, I see the difference is at the call of > InternalGetHostByAddress. > > Code list 1: InternalGetHostByAddress(IPAddress.Parse(address), false, > true); > Code list 2: InternalGetHostByAddress(address, true, false); > > The declaration of InternalGetHostByAddress is: > internal static IPHostEntry InternalGetHostByAddress(IPAddress address, bool > includeIPv6, bool throwOnFailure) > > QSIDeveloper, are you using IPV6 on your side? If we gave a IPV6 address, > the code path in InternalGetHostByAddress is different when the includeIPv6 > param equals true and false. (I do not paste the code of > InternalGetHostByAddress here, but you can see its code with > http://blogs.msdn.com/sburke/archive...urce-code.aspx) > > IPv6 requires the use of getaddrinfo() rather than the traditional IPv4 > gethostbyaddr() / gethostbyname(). getaddrinfo() is also protocol > independant in that it will also resolve IPv4 names / addresses. As a > result, it is the preferred resolution mechanism on platforms that support > it (Windows 5.1+). In other words, if your environment is Window NT4 or 2000 > where getaddrinfo() is unsupported, IPv6 resolution does not work. > QSIDeveloper, would you please check the OS version? > > If IPv6 is disabled, we could detect IPv6 addresses and throw an unsupported > platform exception. > > My additional suggestions that my help you trouble-shoot the issue: > > 1. Debug into the .NET Dsn source code according to the article > http://blogs.msdn.com/sburke/archive...urce-code.aspx, > and step through the code path of GetHostEntry. > > 2. looking at what the DNS interaction is using netmon. > http://www.microsoft.com/downloads/d...displaylang=en > > Hope it helps > > Regards, > Jialiang Ge > Microsoft Online Community Support > > ================================================= > Delighting our customers is our #1 priority. We welcome your comments and > suggestions about how we can improve the support we provide to you. Please > feel free to let my manager know what you think of the level of service > provided. You can send feedback directly to my manager at: > msdnmg@xxxxxx. > > This posting is provided "AS IS" with no warranties, and confers no rights. > ============================================= > > ""Jialiang Ge [MSFT]"" <jialge@xxxxxx> wrote in message > news:iZLUTQr$IHA.4792@xxxxxx Quote: > > Hello QSIDeveloper, > > > > As far as I know, Dns.GetHostEntry returns IP address as the HostName when > > no DNS servers respond to the reverse DNS query. For example, when all DNS > > servers are unreachable. Accompanied with this, the call of > > GetHostByAddress will throw a SocketException with message "The requested > > name is valid, but no data of the requested type was found". However, > > Dns.GetHostByAddress seems working fine on your side. Please give me some > > time. I will look for other reasons for the abnormal behavior of > > GetHostEntry. > > > > For your second question "What is the correct way to get this information > > in .Net 2.0": > > System.Net.Dns.GetHostByAddress is for .Net 1.1 or prior. From .NET 2.0, > > we > > use Dns.GetHostEntry. > > > > Regards, > > Jialiang Ge (jialge@xxxxxx, remove 'online.') > > Microsoft Online Community Support > > > > Delighting our customers is our #1 priority. We welcome your comments and > > suggestions about how we can improve the support we provide to you. Please > > feel free to let my manager know what you think of the level of service > > provided. You can send feedback directly to my manager at: > > msdnmg@xxxxxx. > > > > ================================================== > > Get notification to my posts through email? Please refer to > > http://msdn.microsoft.com/en-us/subs...#notifications. > > > > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues > > where an initial response from the community or a Microsoft Support > > Engineer within 1 business day is acceptable. Please note that each follow > > up response may take approximately 2 business days as the support > > professional working with you may need further investigation to reach the > > most efficient resolution. The offering is not appropriate for situations > > that require urgent, real-time or phone-based interactions or complex > > project analysis and dump analysis issues. Issues of this nature are best > > handled working with a dedicated Microsoft Support Engineer by contacting > > Microsoft Customer Support Services (CSS) at > > http://support.microsoft.com/select/...tance&ln=en-us. > > ================================================== > > This posting is provided "AS IS" with no warranties, and confers no > > rights. > > > > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Dns.GetHostEntry not working the same as Dns.Resolve or Dns.Ge Hello QSIDeveloper Never mind my last reply. I get the product team's confirmation: GetHostEntry tries to do a reverse DNS resolve when an IPaddress is passed. It's very likely that the DNS server you are using does not have the correct reverse lookup data for the IPAddress you are testing with. This is a known issue of GetHostEntry, and it has been fixed in Windows Vista. You could use Dns.GetHostAddresses if you just want the IP Address to be returned without a reverse lookup attempted. Please let me know if you have any other concerns about it. You may also consider contacting Microsoft Customer Support Sercice, which will be free for you in this case because the issue has been confirmed as our product issue. Have a nice weekend! Regards, Jialiang Ge (jialge@xxxxxx, remove 'online.') Microsoft Online Community Support ================================================= Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@xxxxxx. This posting is provided "AS IS" with no warranties, and confers no rights. ================================================= |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Dns.GetHostEntry not working the same as Dns.Resolve or Dns.Ge Hello QSIDeveloper, I am writing to check the status of the issue on your side. Would you mind letting me know the result of the suggestions? If you have any concerns/questions regarding the issue, please DON'T hesitate to tell me. Have a great day! Regards, Jialiang Ge (jialge@xxxxxx, remove 'online.') Microsoft Online Community Support ================================================= Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@xxxxxx. This posting is provided "AS IS" with no warranties, and confers no rights. ================================================= |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| RE: how to resolve IP conflict Issue | Virtual PC | |||
| Can't ping VS or resolve its name on LAN | Virtual Server | |||
| Re: Cannot resolve www | Vista networking & sharing | |||
| Cannot resolve DNS on domain? | Vista networking & sharing | |||
| DNS is not reachable- how do I resolve it? | Vista networking & sharing | |||