Last active
August 29, 2015 14:23
-
-
Save elifarley/748a7c38f5e9c13dcb76 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package java.net; | |
public class GetLocalHostInfo { | |
public static InetAddressImpl impl; | |
public static void main( final String[] args ) { | |
try { | |
InetAddress.getLoopbackAddress(); | |
System.out.println( "java.version : " + System.getProperty( "java.version" ) ); | |
System.out.println( "preferIPv4Stack : " | |
+ System.getProperty( "java.net.preferIPv4Stack" ) ); | |
impl = InetAddressImplFactory.create(); | |
System.out.println( "isIPv6Supported : " + InetAddressImplFactory.isIPv6Supported() ); | |
getInfo(); | |
} catch ( final UnknownHostException e ) { | |
e.printStackTrace(); | |
} finally { | |
System.out.println( "-------------------------------------------------" ); | |
} | |
} | |
static void getInfo() throws UnknownHostException { | |
try { | |
System.out.println( "InetAddressImpl : " + impl.getClass().getName() ); | |
System.out.println( "getLocalHostName: " + impl.getLocalHostName() ); | |
System.out.println( "getLocalHost : " + InetAddress.getLocalHost() ); | |
} catch ( final Exception e ) { | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh¬ | |
¬ | |
(cd /path/to/this/proj && /java/jdk-${1:-8}/bin/java \¬ | |
-Djava.net.preferIPv4Stack=${2:-false} \¬ | |
-Xbootclasspath/p:. java.net.GetLocalHostInfo )¬ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ~/GC-4380/getlocalhostinfo.sh 8 | |
java.version : 1.8.0_45 | |
preferIPv4Stack : false | |
isIPv6Supported : true | |
InetAddressImpl : java.net.Inet6AddressImpl | |
getLocalHostName: mybox | |
getLocalHost : mybox/185.69.214.74 | |
------------------------------------------------- | |
$ ~/GC-4380/getlocalhostinfo.sh 7 | |
java.version : 1.7.0_45 | |
preferIPv4Stack : false | |
isIPv6Supported : true | |
InetAddressImpl : java.net.Inet6AddressImpl | |
getLocalHostName: mybox | |
getLocalHost : mybox/185.69.214.74 | |
------------------------------------------------- | |
$ ~/GC-4380/getlocalhostinfo.sh 7 true | |
java.version : 1.7.0_45 | |
preferIPv4Stack : true | |
isIPv6Supported : false | |
InetAddressImpl : java.net.Inet4AddressImpl | |
getLocalHostName: mybox | |
getLocalHost : mybox/185.69.214.74 | |
------------------------------------------------- | |
$ ~/GC-4380/getlocalhostinfo.sh 8 true | |
java.version : 1.8.0_45 | |
preferIPv4Stack : true | |
isIPv6Supported : false | |
InetAddressImpl : java.net.Inet4AddressImpl | |
getLocalHostName: 185-69-214-74.ded.intelignet.com.br | |
java.net.UnknownHostException: 185-69-214-74.ded.intelignet.com.br: 185-69-214-74.ded.intelignet.com.br: unknown error | |
at java.net.InetAddress.getLocalHost(InetAddress.java:1483) | |
at java.net.GetLocalHostName.getInfo(GetLocalHostName.java:35) | |
at java.net.GetLocalHostName.main(GetLocalHostName.java:18) | |
Caused by: java.net.UnknownHostException: 185-69-214-74.ded.intelignet.com.br: unknown error | |
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) | |
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:907) | |
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1302) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment