regex - How can I make a regular expression for IP address with Subnetmask? -
i have ip address list this:
180.183.0.0/16 180.210.216.0/22 180.214.192.0/19 182.52.0.0/15 ...(400 more)
how can make regular expression ip address subnetmask?
why want this.
i have website load balancer(i can't change config in server), client wants deny access specific country access. use .htaccess this.
setenvif x-forwarded-for "59\.(5[6-9]|6[0-1])\.[0-9]+\." denyip order allow,deny allow deny env=denyip
given list of address in sample text these expressions match requested ranges using alternation match numeric ranges. unfortunately they'll need constructed individually because of how regular expression doesn't evaluate text. match 182.52
or 182.53
string you'd use regex contains desired sub-strings , 182.5[23]
.
- 180.183.0.0/16 has range 180.183.0.1 - 180.183.255.254
^180\.183\.(?:[0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.(?:[1-9][0-9]?|1[0-9]{2}|2[0-4][0-9]|25[0-4])$
- 180.210.216.0/22 has range 180.183.0.1 - 180.183.3.254
^180\.210\.[0-3]\.(?:[1-9][0-9]?|1[0-9]{2}|2[0-4][0-9]|25[0-4])$
- 180.214.192.0/19 has range 180.183.0.1 - 180.183.31.254
^180\.214\.(?:[0-9]|[12][0-9]|3[01])\.(?:[1-9][0-9]?|1[0-9]{2}|2[0-4][0-9]|25[0-4])$
- 182.52.0.0/15 has range 182.52.0.1 - 182.53.255.254
^182\.5[23]\.(?:[0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.(?:[1-9][0-9]?|1[0-9]{2}|2[0-4][0-9]|25[0-4])$
Comments
Post a Comment