`
竹临仙
  • 浏览: 36844 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

得到本机的ip地址

 
阅读更多
public   static   String   getLocalIP()   {
String   ipAdress   =   " ";
String   myHost   =   " ";
InetAddress   myIPaddress   =   null;
try   {
myIPaddress   =   InetAddress.getLocalHost();
myHost   =   myIPaddress.toString();
ipAdress   =   myHost.substring(myHost.indexOf( "/ ")   +   1,   myHost
.length());//   ip部分
}   catch   (UnknownHostException   e)   {
}
return   (ipAdress);
}

public static void main(String[] args) {
System.out.println(getLocalIP());//yangguanlin-PC/172.66.7.25
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics