Forum Moderators: phranque
Perhaps note the right forum, but here goes:
I want to present some text to a browser based upon a range of client IP addresses using SSI. Let's say the client address ranges are two separate class C networks (192.75.10.0/24 and 204.200.10.0/24). I believe I can:
<!--#if expr="$REMOTE_ADDR = /^192\.75\.10\./" -->
You are on 192.75.10.0/24
<!--#elif expr="$REMOTE_ADDR = /^204\.200\.10\./" -->
You are on 204.225.10.0/24
<!--#endif -->
But, how do you write the regular expression for a range like a /19 network such as 208.42.96.0/19?
Thanks in advance.
If this is not the right forum, please advise where I should post.
Welcome to WebmasterWorld!
Sort of a grey area, since regular expressions are used in all kinds of scripts, but since it's an SSI-related question, I'd say this forum is as good as any... :)
First, you have to convert the CIDR spec into a range, and then use the OR function to test for the *lexical* value of the various "parts" of the range. Remember, we are testing for character matches, not numeric values.
> ... a /19 network such as 208.42.96.0/19
Convert to binary:
11010000.00101010.01100000.00000000 (208.42.96.0)
11111111.11111111.11100000.00000000 (/19 netmask)
11010000.00101010.01100000.00000000 (derived base of range)
11010000.00101010.01111111.11111111 (derived top of range)
So, converting back to decimal octets, the range is from 208.42.96.0 to 208.42.127.255
Converting that to a character test:
#if expr="( ($REMOTE_ADDR = /^208\.42\.9[6-9]\./) ¦¦ ($REMOTE_ADDR = /^208\.42\.1[01][0-9]\./) ¦¦ ($REMOTE_ADDR = /^208\.42\.12[0-7]\./) )"
Have fun! (A little pep talk, because this is a lot of work!)
Jim
Thank you for visiting from
<!--#if expr="( ($REMOTE_ADDR = /^192\.192\.10\./) ¦¦
($REMOTE_ADDR = /^192\.192\.16[1-4]\./) ¦¦
($REMOTE_ADDR = /^192\.225\.[8-9]\./) ¦¦
($REMOTE_ADDR = /^192\.225\.1[0-5]\./) ¦¦
($REMOTE_ADDR = /^204\.12\.9[6-9]\./) ¦¦
($REMOTE_ADDR = /^204\.12\.1[01][0-9]\./) ¦¦
($REMOTE_ADDR = /^204\.12\.12[0-7]\./) )" -->
The place that uses these networks at
<!--#endif -->
IP address <!--#echo var="REMOTE_ADDR" -->!