首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

失去本机ip

2012-06-28 
得到本机ippublic String getLocalIpAddress() {? ? try {? ? ? ? for (EnumerationNetworkInterface en

得到本机ip

public String getLocalIpAddress() {? ? 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) {? ? ? ? Log.e(LOG_TAG, ex.toString());? ? }? ? return null;}

热点排行