package com.iapppay.mpisa.excel;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @className: AddressUtils
* @classDescription:
* @author lishiqiang
* @create_date: 2019年4月10日 上午10:27:02
* @update_date:
*/
public class AddressUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(AddressUtils.class);
public static String getLocalAddress() {
String ip =null;
try {
Enumeration<NetworkInterface> networkEnum = NetworkInterface.getNetworkInterfaces();
netlable: while (networkEnum.hasMoreElements()) {
NetworkInterface networkInterface = networkEnum.nextElement();
Enumeration<InetAddress> intAddressEnum = networkInterface.getInetAddresses();
while (intAddressEnum.hasMoreElements()) {
InetAddress inetAddress = intAddressEnum.nextElement();
if (inetAddress.isSiteLocalAddress() && !inetAddress.isLoopbackAddress()
&& !inetAddress.getHostAddress().contains(":")) {
ip = inetAddress.getHostAddress();
break netlable;
}
continue netlable;
}
}
} catch (SocketException e) {
LOGGER.info("get the address error");
}
return ip;
}
}