获取本机ip.

Posted on 2017-12-04 18:48  弯弓射雕的男人  阅读(155)  评论(0编辑  收藏  举报

public static void main(String[] args) {
// TODO Auto-generated method stub
InetAddress ipMsg=null;
try {
ipMsg=ipMsg.getLocalHost();

String localname=ipMsg.getHostName();
String localip=ipMsg.getHostAddress();
System.out.println("名称:"+ localname);
System.out.println("ip :"+localip);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}