Tag:email case Reverse proxy stat header remote request empty alibaba
Package Utils;import com.alibaba.druid.util.stringutils;import javax.servlet.http.httpservletrequest;/** * IP Address * * @ Author Zengwei * @email [email protected] * @date 2018-03-23 22:02 */public class Iputils {/** * Get IP Address * * Using the reverse proxy software such as Nginx, you cannot get IP address through REQUEST.GETREMOTEADDR () * If you use a multilevel reverse proxy, the value of x-forwarded-for is more than one, but a string of IP addresses, * The first non-unknown valid IP string in x-forwarded-for is the real IP address */public static string getipaddr (HttpServletRequest request) {string IP = null; try {ip = request.getheader ("X-forwarded-for"); if (Stringutils.isempty (IP) | | "Unknown". Equalsignorecase (IP)) {IP = request.getheader ("Proxy-client-ip"); } if (Stringutils.isempty (IP) | | | ip.length () = = 0 | | "Unknown". Equalsignorecase (IP)) {IP = request.getheader ("Wl-proxy-client-ip"); } if (Stringutils.isempty (IP) | | "Unknown". Equalsignorecase (IP)) {IP = request.getheader ("Http_client_ip"); } if (Stringutils.isempty (IP) | | "Unknown". EqualsignorecasE (IP)) {IP = request.getheader ("Http_x_forwarded_for"); } if (Stringutils.isempty (IP) | | "Unknown". Equalsignorecase (IP)) {IP = request.getremoteaddr (); }} catch (Exception e) {} return IP; }}
Java Get IP Address