The simplest way to achieve it is to implement a standard servlet filter (javax.servlet.Filter) and register it in your web.xml
In the doFilter method you get an object representing the request from which you can obtain source IP and path information.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String ipAddress = httpRequest.getRemoteAddr();
String path = httpRequest.getPathInfo();
// do the filtering based on ipAddress and path
// pass the request along the filter chain
chain.doFilter(request, response);
}