Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to block a IP address using web.xml?

How can I block a ip address with some configuration on web.xml?

Do I need a filter? How can I implement one?

like image 953
BrunoLM Avatar asked May 19 '10 21:05

BrunoLM


People also ask

Can you blacklist an IP address?

A website may be IP blacklisted if its content is deemed inappropriate. This could be pornographic material, black market trade, or sensitive subjects such as weapons and arms deals. Internet Service Providers or even government agencies could actively block websites such as these and prevent users from accessing them.

How do I block an IP with Cloudflare?

In the Cloudflare dashboard, navigate to Firewall > Tools. Cloudflare tools dashboard. To create a new IP access rule, add an IP address, select the “Block” action, select “This Website” (or “All Websites in Account” if you want the rule to apply across all your Cloudflare domains), and click “Add”.


1 Answers

You can't do this purely through config in web.xml, no. A servlet filter would be a good place to implement such a thing, though.

The Filter interface supplies the HttpServletRequest as part of the filter chain invocation, and from that you can get the IP address of the client (using getRemoteAddr), and compare that to your list of permitted addresses.

Alternatively, your specific appserver might support IP filtering at a proprietary level, but that locks you into that container (which may or may not be a problem for you).

like image 69
skaffman Avatar answered Sep 28 '22 14:09

skaffman