java怎么获取当前ip
收起
云计算小粉
2018-05-10 20:07:24
2623
0
2
条回答
写回答
取消
提交回答
-
import java.net.*;
public class Test6 {
public static void main(String[] args) {
// TODO Auto-generated method stub
InetAddress ia=null;
try {
ia=ia.getLocalHost();
String localname=ia.getHostName();
String localip=ia.getHostAddress();
System.out.println("本机名称是:"+ localname);
System.out.println("本机的ip是 :"+localip);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
2019-07-17 22:15:23
-
java.net.InetAddress.getLocalHost().getHostAddress()
2019-07-17 22:15:23