java中如何自动获取电脑的ip地址?

String ip=InetAddress.getLocalHost().getHostAddress().toString();

可以写一个main方法测试一下。