开发者

getCanonicalHostName for localhost works on Win 7 but not XP?

开发者 https://www.devze.com 2023-02-28 08:34 出处:网络
The following simple code works fine o开发者_如何学JAVAn Windows 7, returning a fully-qualified name (e.g. \'myhost.x.com\'). However, when run on Windows XP machines in the same network, it returns o

The following simple code works fine o开发者_如何学JAVAn Windows 7, returning a fully-qualified name (e.g. 'myhost.x.com'). However, when run on Windows XP machines in the same network, it returns only the hostname (e.g. 'myhost'). Is this a known issue? Any workarounds?

hostName = InetAddress.getLocalHost().getCanonicalHostName();

Context: want to match up processes from the same originating machine on a remote server. The client processes pass in their hostname so that the server can group requests from the same client machine even when they are from different apps on that machine. We're seeing mismatches for apps running on client machines using XP when one client process is Java and the other is C# because one is fully-qualified and one is not. Windows 7 clients work fine. Initially thought it was .NET that was not obtaining the FQDN on XP, but now it appears to be Java clients using the code above.

Update: on same XP machine, a C++ client (not .NET) is also able to get the full-qualified name. So it seems that of the three, only java on this machine is unable to obtain the FQDN using this API. This is Java 1.6.0_20-b02. Also, the code in Java and C++ needs to work on non-windows platforms as well.


The documentation for the method - http://download.oracle.com/javase/6/docs/api/java/net/InetAddress.html#getCanonicalHostName() - says

"Gets the fully qualified domain name for this IP address. Best effort method, meaning we may not be able to return the FQDN depending on the underlying system configuration."

I believe that Java asks the resolver in the operating system which apparently is different on 7 and XP. Anyway this request can be nixed by the SecurityManager, meaning that you may have to reconsider your identification process. Perhaps even do the DNS-lookup yourself based on all the IP-numbers the machine has.

What is the information you need and why?

0

精彩评论

暂无评论...
验证码 换一张
取 消