a more complete way to get a visitor's IP
#
Import Javax.servlet.http.HttpServletRequest; /** * Created by Tan Jian on 2017/8/11.
14:53. *©all Rights Reserved. * * Network-related tools/public class Network {/** * get a request to initiate the IP * @param request HttpServletRequest * @retur
n String Type IP/public static string Getremoteip (HttpServletRequest request) {string IP;
ip = Request.getheader ("X-forwarded-for");
if (Isnullip (IP)) {IP = request.getheader ("Proxy-client-ip");
} if (Isnullip (IP)) {IP = request.getheader ("Wl-proxy-client-ip");
} if (Isnullip (IP)) {IP = request.getheader ("Http_client_ip");
} if (Isnullip (IP)) {IP = request.getheader ("Http_x_forwarded_for");
} if (Isnullip (IP)) {IP = request.getremoteaddr ();
} if (Ip.contains (",")) {Ip=ip.split (",") [0]; } if ("0.0.0.0.0.0.0.1". Equals (IP) | |
"0.0.0.0.0.0.0.1%0". Equals (IP)) { ip = "127.0.0.1";
} return IP; } private static Boolean Isnullip (final String IP) {return IP = null | | ip.length () = 0 | |
"Unknown". Equalsignorecase (IP);
}
}