inetaddress

UnknowHostException cannot recover when network is back but restart JVM solved it

跟風遠走 提交于 2020-01-16 10:32:04
问题 From one timepoint, our JVM(In fact a Yarn NodeManager) start to report UnknownHostException; It is reported by JVM code return InetAddress.getByName(host); for the next more than 2 days, the exception always exists; During the time it is reporting this error, I do the following test: During the error happening, ping could succeed and get the IP address(Very weird); During the error, I write a simple test case to check the hostname resolve, it also could succeeded: After we restarted the JVM,

UnknowHostException cannot recover when network is back but restart JVM solved it

拥有回忆 提交于 2020-01-16 10:30:08
问题 From one timepoint, our JVM(In fact a Yarn NodeManager) start to report UnknownHostException; It is reported by JVM code return InetAddress.getByName(host); for the next more than 2 days, the exception always exists; During the time it is reporting this error, I do the following test: During the error happening, ping could succeed and get the IP address(Very weird); During the error, I write a simple test case to check the hostname resolve, it also could succeeded: After we restarted the JVM,

When the DNS lookup occurs in this code? By getByName() or getHostName() or getHostAddress()?

别说谁变了你拦得住时间么 提交于 2020-01-07 04:59:09
问题 In which line the DNS lookup occurs? import java.net.InetAddress; import java.net.UnknownHostException; public class Addresses { public static void main(String[] args) { try { InetAddress address= InetAddress.getByName("www.sun.com"); //line 7 System.out.println(address.getHostName()+ "-"+address.getHostAddress());//line 8 } catch (UnknownHostException e) { e.printStackTrace(); } } } As I can understand it should be at line 7. But in a set of tutorials I found that it is said to be at line 8.

InetAddress java 8 is not getting the hostname

送分小仙女□ 提交于 2019-12-30 10:07:50
问题 InetAddress.getLocalHost().getHostName() is no more getting the name of the HostName since I switched to java 8 ... with the jdk1.8 the InetAddress.getLocalHost().getHostName() returns "localhost". Before (when I was using jdk1.6) it gives me the right hostname (which is "ACTION03") according to the network config : cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=ACTION03 any help ? 回答1: Works for me on Linux (Ubuntu 14.04) with Java 1.8.0_05. public class HostName { public static void

InetAddress java 8 is not getting the hostname

会有一股神秘感。 提交于 2019-12-30 10:07:13
问题 InetAddress.getLocalHost().getHostName() is no more getting the name of the HostName since I switched to java 8 ... with the jdk1.8 the InetAddress.getLocalHost().getHostName() returns "localhost". Before (when I was using jdk1.6) it gives me the right hostname (which is "ACTION03") according to the network config : cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=ACTION03 any help ? 回答1: Works for me on Linux (Ubuntu 14.04) with Java 1.8.0_05. public class HostName { public static void

How can I bind serversocket to specific IP?

只愿长相守 提交于 2019-12-23 07:47:27
问题 If I have a String representing an IP address (IPv4 or IPv6) how can I create a ServerSocket and bind to this IP without caring if the IP passed in, is IPv4 or IPv6? I see that there is a constructor: ServerSocket(int port, int backlog, InetAddress bindAddr) but InetAddress does not seem to offer any constructors and its subclasses have names specific to IPv4 and IPv6. So how can I bind the socket to the IP? 回答1: You can use the factory method INetAddress.getByName. It'll figure out which

DNS query in JAVA

旧街凉风 提交于 2019-12-21 09:29:45
问题 I am messing around with DNS services in Java - I am specifically trying to lookup all google.com addresses and display them in an array, similar to running a lookup using nslookup: nslookup -q=TXT _netblocks.google.com 8.8.8.8 I am using InetAddress for this but keep on getting exception errors. Since the errors refer to 'Unknown Host' I don't think InetAddress can read TXT records (if I use google.com it works, but that does't show the full IP Range). Below is my code: InetAddress dnsresult

Host Name Vs Canonical Host Name

假装没事ソ 提交于 2019-12-20 16:36:06
问题 Can anyone please explain me the difference between Host Name and Canonical Host Name? I am currently using InetAddress class to fetch host name using the IP Address. I came across these 2 APIs. So I am just wondering, which one I should opt for? 回答1: There are a few difference between the two: getCanonicalHostName() will attempt to resolve the FQDN. Therefore, you would get foo.mycompany.com whereas getHostName() might just return foo . getCanonicalHostName() will always do a reverse DNS

Host Name Vs Canonical Host Name

别来无恙 提交于 2019-12-20 16:34:27
问题 Can anyone please explain me the difference between Host Name and Canonical Host Name? I am currently using InetAddress class to fetch host name using the IP Address. I came across these 2 APIs. So I am just wondering, which one I should opt for? 回答1: There are a few difference between the two: getCanonicalHostName() will attempt to resolve the FQDN. Therefore, you would get foo.mycompany.com whereas getHostName() might just return foo . getCanonicalHostName() will always do a reverse DNS

Java InetAddress.isReachable() timeout

余生长醉 提交于 2019-12-19 06:06:47
问题 I am trying to find out if specific hosts on my network are reachable. My java code is as follows: InetAddress adr = InetAddress.getByName(host); if(adr.isReachable(3000)){ System.out.println(host + " is reachable"); } This works quite well, however if I lower the timeout to say 500ms instead, it will not designate the host reachable anymore. I plan to check quite a few hosts in a loop, so having a low timeout is quite important. If I ping the host manually from the windows command line, it