Public String getipaddr () {
HttpServletRequest request = Getrequest ();
String IP = request.getheader ("X-forwarded-for");
if (Stringutils.isnullorempty (IP) | | "Unknown". Equalsignorecase (IP)) {
ip = Request.getheader ("X-forwarded-for");
}
if (Stringutils.isnullorempty (IP) | | "Unknown". Equalsignorecase (IP)) {
ip = Request.getheader ("Proxy-client-ip");
}
if (Stringutils.isnullorempty (IP) | | "Unknown". Equalsignorecase (IP)) {
ip = Request.getheader ("Wl-proxy-client-ip");
}
if (Stringutils.isnullorempty (IP) | | "Unknown". Equalsignorecase (IP)) {
ip = Request.getheader ("Http_client_ip");
}
if (Stringutils.isnullorempty (IP) | | "Unknown". Equalsignorecase (IP)) {
ip = Request.getheader ("Http_x_forwarded_for");
}
if (Stringutils.isnullorempty (IP) | | "Unknown". Equalsignorecase (IP)) {
ip = request.getremoteaddr ();
}
if (! Stringutils.isnullorempty (IP) &&ip.indexof (",")!=-1) {
ip = ip.substring (Ip.lastindexof (",") + 1, ip.length ()). Trim ();
}
Logger.info ("X-forwarded-for:" +request.getheader ("X-forwarded-for"));
Logger.info ("Proxy-client-ip:" +request.getheader ("Proxy-client-ip"));
Logger.info ("Wl-proxy-client-ip:" +request.getheader ("Wl-proxy-client-ip"));
Logger.info ("Http_client_ip:" +request.getheader ("Http_client_ip"));
Logger.info ("Http_x_forwarded_for:" +request.getheader ("Http_x_forwarded_for"));
Logger.info ("Http_client_ip:" +request.getheader ("Http_client_ip"));
Logger.info ("Remote_ip:" +request.getremoteaddr ());
Return Ip.equals ("0:0:0:0:0:0:0:1")? " 127.0.0.1 ": IP;
}
public static Boolean isnullorempty (String str) {
return str = = NULL | | ". Equals (str) | |" Null ". Equals (str);
}
IsNullOrEmpty method for own writing, slightly modified under
IP Address Acquisition