2012-01-03 47 views
0

任何人都可以請建議我如何獲得包含IPV4和IPV6地址的IPV6地址的主機名。如何從主機名獲得IPV6地址

我試着用java.net.InetAddress.getHostAddress得到它,但它只是給了我ipv4。

回答

1

使用InetAddress.getAllByName("your.host.name")。根據JavaDoc:

Given the name of a host, returns an array of its IP addresses, based on the configured name service on the system. 
1

,你應該能夠使用

java.net.inet6address.getHostAddress 
2

你將不得不使用java.net.Inet6Address.getHostAddress()