相关文章推荐
暴走的茴香  ·  打开Anaconda Navigator ...·  1 年前    · 
稳重的钥匙扣  ·  python+selenium ...·  1 年前    · 
果断的火柴  ·  How to ...·  1 年前    · 
至今单身的杨桃  ·  Java BufferedReader ...·  1 年前    · 
微笑的白开水  ·  禁用div元素 —— ...·  1 年前    · 
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 property is System.setProperty("java.net.preferIPv6Addresses","true") – Vinod Sep 9, 2013 at 11:27 @vinod please write that as an answer (possible immediately) and mark it as accepted (possible after two days) – John Dvorak Sep 9, 2013 at 11:34

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.