不说别的,直接上代码和运行结果图:
代码:
public static void main(String[] args) throws UnknownHostException {
    InetAddress inetAddress = InetAddress.getLocalHost();
    System.err.print("主机名:");
    System.out.println(inetAddress.getHostName());
    System.err.println("本机的所有ip地址的列表:---");
    Arrays.stream(InetAddress.getAllByName(inetAddress.getHostName())).forEach(i -> System.out.println(i.getHostAddress()));
}
运行结果:我现在连接的是WiFi,这个ip地址就是,但是没有获取到,不知道是否有大佬可以指点小弟一下