{"id":204,"date":"2004-08-13T13:16:18","date_gmt":"2004-08-13T12:16:18","guid":{"rendered":"http:\/\/wp.devco.net\/?p=204"},"modified":"2009-10-09T17:18:52","modified_gmt":"2009-10-09T16:18:52","slug":"calculating_cidr_notation_from_ip_ranges","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2004\/08\/13\/calculating_cidr_notation_from_ip_ranges.php","title":{"rendered":"Calculating CIDR notation from IP ranges"},"content":{"rendered":"

Following from my previous<\/a> post about blocking some more countries I discovered a bit of a short coming in the code I used to calculate CIDR notation from ranges of IP’s. So a bit of searching on CPAN got me Net::CIDR<\/a>.<\/p>\n

\nuse Net::CIDR;
\n$range = shift;
\nprint (join(“\\n”, Net::CIDR::range2cidr(“$range”)) . “\\n” );\n<\/p><\/blockquote>\n

This will take any given range of ip address in format a.b.c.d-w.x.y.z and spew out a list of subnets required to cover the whole range:<\/p>\n

\n# .\/range2cidr.pl 64.139.147.0-64.139.170.255
\n64.139.147.0\/24
\n64.139.148.0\/22
\n64.139.152.0\/21
\n64.139.160.0\/21
\n64.139.168.0\/23
\n64.139.170.0\/24\n<\/p><\/blockquote>\n

So with this I now have hopefully a more accurate set of rules that will not block bits of New Zeeland as well by accident.<\/p>\n","protected":false},"excerpt":{"rendered":"

Following from my previous post about blocking some more countries I discovered a bit of a short coming in the code I used to calculate CIDR notation from ranges of IP’s. So a bit of searching on CPAN got me Net::CIDR. use Net::CIDR; $range = shift; print (join(“\\n”, Net::CIDR::range2cidr(“$range”)) . “\\n” ); This will take […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","footnotes":""},"categories":[7],"tags":[121,26,46],"_links":{"self":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/204"}],"collection":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/comments?post=204"}],"version-history":[{"count":1,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":780,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/204\/revisions\/780"}],"wp:attachment":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/media?parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/categories?post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/tags?post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}