废话少说,直接上代码(java)
命令行输出的就是本机的IPv6地址
package app; import java.net.Inet6Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; public class IPv6 { public static void main(String[] args) { /*获取本机所有ip地址(包括保留地址,ipv4,ipv6 如果安装了虚拟机会更多其他的地址) * try { InetAddress ads = null; Enumerationadds = NetworkInterface.getNetworkInterfaces(); while(adds.hasMoreElements()) { EnumerationinetAds = adds.nextElement().getInetAddresses(); while(inetAds.hasMoreElements()) { ads = inetAds.nextElement(); System.out.println(ads.getHostAddress()); } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ //获取可用ipv6