展会信息港展会大全

如何获取ip地址
来源:互联网   发布日期:2016-01-14 11:30:55   浏览:2189次  

导读:public static String getIpAddress() { try{ for(EnumerationNetworkInterface en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();){ NetworkInterface intf = en.nextElement(); for (EnumerationInetAddress enumIpAddr = intf.getIne...

public static String getIpAddress() {

try{

for(Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();){

NetworkInterface intf = en.nextElement();

for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();){

InetAddress inetAddress = enumIpAddr.nextElement();

if (!inetAddress.isLoopbackAddress()){

return inetAddress.getHostAddress().toString();

}

}

}

}catch (SocketException ex){

ex.printStackTrace();

}

return null;

}

public static int getIpAddress() {

WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);

WifiInfo wifiInfo = wifiManager.getConnectionInfo();

return wifiInfo.getIpAddress();

}

赞助本站

人工智能实验室

相关热词: android开发 android教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港