【Java】得到本机IP
import java.net.InetAddress; import java.net.UnknownHostException; public class MainProcess { public static void main(String[] args) { InetAddress localhost = null; try { localhost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { e.printStackTrace(); } System.out.println ("localhost: "+localhost.getHostAddress()); System.out.println ("localhost: "+localhost.getHostName()); } }