80,351
社区成员
发帖
与我相关
我的任务
分享
public String getEthernetIPAddr() {
String ip = null;
try {
Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
InetAddress ia;
while (netInterfaces.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface)netInterfaces.nextElement();
if (ni.getName().equals(mInterfaceName)) {
Enumeration<InetAddress> address = ni.getInetAddresses();
while (address.hasMoreElements()) {
ia = address.nextElement();
if (!ia.isLoopbackAddress() && (ia.getHostAddress().indexOf(":")==-1)) {
ip = ia.getHostAddress();
if (localLOGV) Slog.v(TAG, "getIP: " + ip);
break;
}
}
}
}
}
catch (SocketException e) {
e.printStackTrace();
}
return ip;
}