Forum Moderators: phranque
You're right, it does not block 162.0 through 162.255.
The easiest way to do that is to use two RewriteConds, one blocking 000.161.128-255.x and the other blocking 000.162.x.x, both of which are easy to derive from what you've already got. After working them out, you can combine them into one RewriteCond if desired.
RewriteCond %{REMOTE_ADDR} ^000\.161\.(12[89]¦1[3-9][0-9]¦2[0-5][0-9])\. [OR]
RewriteCond %{REMOTE_ADDR} ^000\.162\.
Note that "it doesn't hurt anything" to test for 200-259, or even 200-299, even though you will never get a request for an IP address octet value above 255 -- This saves some filespace and processing time.
Also, remember that mod_rewrite is not capable of doing a numerical-range compare, it is doing a character-range compare. In otherwords, mod_rewrite has no idea that these are 'numbers'. That sometimes clarifies things.
Jim
RewriteCond %{REMOTE_ADDR} ^000\.(161\.(12[89]¦1[3-9][0-9]¦2[0-5][0-9])¦162)\.
Jim
RewriteCond %{REMOTE_ADDR} ^000\.(160¦161\.([1-8]?[0-9]¦9[0-5]))\. [OR]
BTW, we're not really in the business of pre-test code reviews here. I'm only commenting because of the tweaks that are possible to your code. It's really more in line with our charter to test first, then post if there is a problem.
It's true you can't test by using someone else's IP address, but you can use an on-line regex tester, or put the IP to match against the regex into a query string, and rewrite to one of two pages that give you an 'in-range' or 'out-of-range' result based on that regex:
# If query string matches regex, show "match" page
RewriteCond %{QUERY_STRING} ^000\.(160¦161\.([1-8]?[0-9]¦9[0-5]))\.
RewriteRule ^test_ip\.html$ ^http://www.example.com/match_found.html$ [R=301,L]
#
# Else show "no match" page
RewriteRule ^test_ip\.html$ ^http://www.example.com/no_match_found.html$ [R=301,L]
That's just one example -- There are many ways to test otherwise "untestable" regex patterns. Just think outside the box and change the server variable you use to test the regex.
Jim
[edited by: jdMorgan at 8:27 pm (utc) on Aug. 18, 2006]