change mysql
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package com.newyetai.common.util;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -168,12 +171,24 @@ public class RequestUtils {
|
||||
String hostname = System.getenv("HOSTNAME");
|
||||
String hostIp = InetAddress.getByName(hostname).getHostAddress();
|
||||
if ("127.0.0.1".equals(hostIp) || "0:0:0:0:0:0:0:1".equals(hostIp)) {
|
||||
return InetAddress.getLocalHost().getHostAddress();
|
||||
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
||||
while (interfaces.hasMoreElements()) {
|
||||
NetworkInterface iface = interfaces.nextElement();
|
||||
if (iface.isUp() && !iface.isLoopback()) {
|
||||
Enumeration<InetAddress> addresses = iface.getInetAddresses();
|
||||
while (addresses.hasMoreElements()) {
|
||||
InetAddress addr = addresses.nextElement();
|
||||
if (addr instanceof Inet4Address) {
|
||||
return addr.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return hostIp;
|
||||
} catch (UnknownHostException e) {
|
||||
} catch (Exception e) {
|
||||
return "127.0.0.1";
|
||||
}
|
||||
return "127.0.0.1";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user