/**
* @Time 2015.08.05 Wednesday 10:57
* @author zgx
* */
private String flagIpv6 = "::";
private String getDevIp(){
String err = "no ip ";
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
if (intf.getName().toLowerCase().equals("eth0") || intf.getName().toLowerCase().equals("wlan0")) {
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
String ipaddress = inetAddress.getHostAddress().toString();
if(!ipaddress.contains(flagIpv6)){//ipV6的地址
return ipaddress;
}
}
}
}else {
continue;
}
}
} catch (SocketException ex) {
Log.e(TAG, "getDevIp : SocketException ");
} catch (Exception e) {
Log.e(TAG, "getDevIp : Exception ");
}
return err;
}