This article talks about adding Static Host List with IP address in form of a regular expression.
We can add a static host list on CPPM by navigating to Configuration » Identity » Static Host Lists.
Tips about writing a regular expression.
IP Addresses have a particular form.
number.number.number.number
Where the number can be pretty much any number from 0 to 255.
Valid : 1.2.3.4 10.10.10.10 230.245.250.131
Invalid: 1023.10.1.2 256.1.2.3 230.245.270.131
Lets note the immediate observations:
a: 4 numbers, each separated by a single dot
b: 3 dots in total
c: each number can be from 1 to 3 digits in length
d: each number can be from 0 to 255
The base solution would be
.*\..*\..*\..*
Improvising it we would get
[0-9]|[0-9][0-9]|[0-9][0-9][0-9]
This means that we may have
A single digit: [0-9]
OR
1 or 2 or 3 digits?
Better way to write the same would be : [0-9]{1,3}
where items with curly brackets: {min,max}
So the complete IP would be
[0-9]{1,3} \. [0-9]{1,3} \. [0-9]{1,3} \. [0-9]{1,3}
But the above solution is very generic and would allow invalid IPs like 999.999.999.999 also. This is just a base line solution for IP address.
Below is a Real Example.
Allowed IP Range is : 192.18.0.0 - 192.19.31.255
Break down of Range
192.18.
192.19.0 to 31.
and
192.19.[0-9].
192.19.1[0-9].
192.19.2[0-9].
192.19.30.
192.19.31.
Combining both we can write en expression as below.
^
192\.
(
18\.
|
19\.
(
[0-9]\.
|
1[0-9]\.
|
2[0-9]\.
|
30\.
|
31\.
)
)
We can remove a few "\" and re-write the expression as shown below.
^192\.
(
18\.|
19\.
(
[0-9]|1[0-9]|2[0-9]|30|31
)
\.
)