Android 获取设备网卡信息

 public String getServerIP(){
    	StringBuilder IFCONFIG=new StringBuilder();  
    	   try {  
    	       for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {  
    	           NetworkInterface intf = en.nextElement();  
    	           for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {  
    	               InetAddress inetAddress = enumIpAddr.nextElement();  
    	               if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress() && inetAddress.isSiteLocalAddress()) {  
    	               IFCONFIG.append(inetAddress.getHostAddress().toString()+"\n");  
    	               }  
    	  
    	           }  
    	       }  
    	   } catch (SocketException ex) {  
    	   }  
    	   System.out.println("ip地址-----"+IFCONFIG);  
    	   return IFCONFIG.toString();
    }

你可能感兴趣的:(Android笔记)