- /**
- * Get the real IP address of the HTTP request
- * @param request
- * @return
- */
- //Cjianquan 2016/8/2
- public static String getipaddr (HttpServletRequest request) {
- if (request = = null)
- return null;
- String IP = request.getheader ("x-forwarded-for");
- if (IP = = Null | | ip.length () = = 0 | | "Unknown". Equalsignorecase (IP))
- ip = Request.getheader ("Proxy-client-ip");
- if (IP = = Null | | ip.length () = = 0 | | "Unknown". Equalsignorecase (IP))
- ip = Request.getheader ("Wl-proxy-client-ip");
- if (IP = = Null | | ip.length () = = 0 | | "Unknown". Equalsignorecase (IP))
- ip = Request.getheader ("http_client_ip");
- if (IP = = Null | | ip.length () = = 0 | | "Unknown". Equalsignorecase (IP))
- ip = Request.getheader ("http_x_forwarded_for");
- if (IP = = Null | | ip.length () = = 0 | | "Unknown". Equalsignorecase (IP))
- ip = request.getremoteaddr ();
- if ("127.0.0.1". Equals (IP) | | "0:0:0:0:0:0:0:1". Equals (IP))
- try {
- ip = Inetaddress.getlocalhost (). gethostaddress ();
- }
- catch (Unknownhostexception unknownhostexception) {
- }
- return IP;
- }
Get the real IP address of the HTTP request