且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无需连接到互联网即可获取本地IP地址

更新时间:2022-06-22 22:47:33

fe80:0:0:0:226:4aff:fe0d :592e是你的ipv6地址; - )。

fe80:0:0:0:226:4aff:fe0d:592e is your ipv6 address ;-).

使用

if (current_addr instanceof Inet4Address)
  System.out.println(current_addr.getHostAddress());
else if (current_addr instanceof Inet6Address)
  System.out.println(current_addr.getHostAddress());

如果您只关心IPv4,那么只需丢弃IPv6案例。但要注意,IPv6是未来的^^。

If you just care for IPv4, then just discard the IPv6 case. But beware, IPv6 is the future ^^.

PS:检查你的某些中断是否应该是继续 s。

P.S.: Check if some of your breaks should have been continues.