Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am trying to test a java program for IPv6 support on my local system having Windows 7 OS. I have assigned an IPv6 address and have disabled IPv4 in Network Connection.
When I execute
ipconfig
command I get IPv6 address as output.
However, when I execute below java code I get
127.0.0.1
which is an IPv4 address
System.setProperty("java.net.preferIPv6Stack","true");
InetAddress addr = InetAddress.getLocalHost();
System.out.println(addr.getHostAddress());
As per my understanding the above code should print 0:0:0:0:0:0:0:1
.
Have I missed something?
–
–
Problem is resolved. I was setting wrong System property. Correct system property that needs to be set is
System.setProperty("java.net.preferIPv6Addresses","true")
After setting this property the IPv6 address assigned in Network Connection will be displayed.
IPv6 loopback address can be retrieved using below code.
InetAddress.getLoopbackAddress().getHostAddress()
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.