1/20/11

CIDR RegEx shortcuts

POSIX RegEx shortcuts I found that made my life easier that I used with PostFix header maps for dealing with IP addresses


/19 subnets
0-31
([12]?[0-9]|3[01])

32-63
(3[2-9]|[45][0-9]|6[0-3])


64-95
(6[4-9]|[78][0-9]|9[0-5])


96-127
(9[6-9]|1[01][0-9]|12[0-7])


128-159
(12[89]|1[3-5][0-9])


160-191
(1[6-8][0-9]|19[01])


192-223
(19[2-9]|2[01][0-9]|22[0-3])


224-255
(22[4-9]|2[34][0-9]|25[0-5])





/18 subnets

0-63
([1-5]?[0-9]|6[0-3])

64-127
(6[4-9]|[7-9][0-9]|1[01][0-9]|12[0-7])

128-191
(12[89]|1[3-8][0-9]|19[01])

192-255
(19[2-9]|2[0-4][0-9]|25[0-5])



/17 subnets

0-127
([1-9]?[0-9]|1[01][0-9]|12[0-7])

128-255
(12[89]|1[3-9][0-9]|2[0-4][0-9]|25[0-5])


/16 subnets

0-255
([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])


Example Usage with PostFix header_checks map to discard email traffic from a repeat spammer network:

if /^Received:/
/^Received: from .*\[93\.(13[6-9]|14[0-3])\.([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\]/ Discard Croatia Spammers
endif



Source:The Scrutinizer

Quick HTTP to HTTPS - Apache2

There are several methods for redirecting your Apache-based website visitors who might type your servers URL using the plain (non-secure) HT...