public static void getIp() throws Exception {
InetAddress[] inetAddress = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
System.out.println("host Name:"+ InetAddress.getLocalHost().getHostName());
for (InetAddress addr : inetAddress) {
System.out.println(addr.getHostName() + "\t"+ addr.getHostAddress());
}
}
输出结果是一堆地址,接下来贴图:
PC201305102250是我的win7系统的计算机全名,
169.254.227.166 这个叫做保留地址,预防主机得不到ip时准备的地址
192.168.1.46 192.168.191.1 在ip地址分类上属于私有地址c类,具体分类标准可以查资料了解下。
fe80开头的ipv6的链路本地单播地址,对此不大了解。