Java gets access to the user's client IP (for public and local area networks)
/** * Get access to the user's client IP (for public and local area networks). */public static final String getipaddr (final httpservletrequest request) throws Exception {if (request = = null) {throw (new Exception ("Getipaddr method httpservletrequest Object is null"));} String ipstring = Request.getheader ("x-forwarded-for"); if (Stringutils.isblank (ipstring) | | "Unknown". Equalsignorecase (ipstring)) {ipstring = Request.getheader ("Proxy-client-ip");} if (Stringutils.isblank (ipstring) | | "Unknown". Equalsignorecase (ipstring)) {ipstring = Request.getheader ("Wl-proxy-client-ip");} if (Stringutils.isblank (ipstring) | | "Unknown". Equalsignorecase (ipstring)) {ipstring = Request.getremoteaddr ();} Multiple routes, take the first non-unknown ipfinal string[] arr = Ipstring.split (","); for (final String Str:arr) {if (!) Unknown ". Equalsignorecase (str)) {ipstring = Str;break;}} return ipstring;}