简体   繁体   中英

Java back-end check IP and block

I have REST API. Front Vue and back Java + Spring. Where I can find any example how to check IP address of request for my login page to make it save? I need to block IP address on Back End if there was 10 wrong attepts of login, for example.

Thanks to all in future, for any kind of help!

Take a look at this code.

String remoteAddr = "";
        if (request != null) {
            remoteAddr = request.getHeader("X-FORWARDED-FOR");
            if (remoteAddr == null || "".equals(remoteAddr)) {
                remoteAddr = request.getRemoteAddr();
            }
        }

You can find the IP address from your request object into your Rest API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM