In the documentation, the following IP address ranges are treated as private/internal:
10.0.0.0 - 10.255.255.255 8 bits prefix
172.16.0.0 - 172.31.255.255 12 bits prefix
192.168.0.0 - 192.168.255.255 16 bits prefix
The strategy is to match each range with a regex and use "|" to match either one of them. The individual regex are:
Note: one thing to mention about this is that these three expressions don't match "exactly" the IP address format, mainly because they don't check the range (0 to 255) in the atomic expression (?>\.\d{1,3}). However, as long as your IP address comes from a trusted source (e.g., http header), you won't face this problem.
After getting each individual regex, I just package them with match string start (\A) and end (\z), and separate them with "|". Here is the results:
You can go to regular expression 101 to test it.
No comments:
Post a Comment