Java get local IP [duplicate]
问题 This question already has answers here : Getting the IP address of the current machine using Java (17 answers) Closed 6 years ago . Im trying to get the local IP. It should work with System.out.println(Inet4Address.getLocalHost().getHostAddress()); or InetAddress addr = InetAddress.getLocalHost(); ip = addr.getHostAddress(); System.out.println("Ip: " + ip); but it always returns 192.168.178.154 instead of 192.168.178.119 (This is my real local IP(Terminal --> ifconfig )) What should I do? 回答1