/*** Get access to the user's client IP (for public and local area networks). */ Public Static FinalString Getipaddr (Finalhttpservletrequest request)throwsException {if(Request = =NULL) { Throw(NewException ("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 IP Finalstring[] arr = Ipstring.split (","); for(FinalString Str:arr) { if(!" Unknown. Equalsignorecase (str)) {ipstring=str; Break; } } returnipstring; }
Java gets the IP address of the Web login