note 75922 added to ref.network

From: Date: Thu, 21 Jun 2007 15:12:19 +0000
Subject: note 75922 added to ref.network
Groups: php.notes 
Request: Send a blank email to php-notes+get-127868@lists.php.net to get a copy of this message
Here a IP-Range to CIDRs function that I wrote for the purpose of filling my Postfix client.cidr with ripe-ncc data to block spamming from useless countries. Strcmp functions are meant to work around the silly PHP string comparison which inevitably tries compare strings as numbers when possible. I'll make no comment about that fact ... bit I have to bite my tong hard : function PlageVersCIDRs($ip_min, $ip_max) { $cidrs = array(); $ip_min_bin = sprintf('%032b', $ip_min); $ip_max_bin = sprintf('%032b', $ip_max); $ip_cour_bin = $ip_min_bin; while (strcmp($ip_cour_bin, $ip_max_bin) <= 0) { $lng_reseau = 32; $ip_reseau_bin = $ip_cour_bin; while (($ip_cour_bin[$lng_reseau - 1] == '0') && (strcmp(substr_replace($ip_reseau_bin, '1', $lng_reseau - 1, 1), $ip_max_bin) <= 0)) { $ip_reseau_bin[$lng_reseau - 1] = '1'; $lng_reseau--; } $cidrs[] = long2ip(bindec($ip_cour_bin)).'/'.$lng_reseau; $ip_cour_bin = sprintf('%032b', bindec($ip_reseau_bin) + 1); } return $cidrs; } ---- Server IP: 194.153.94.10 Probable Submitter: 82.67.8.86 ---- Manual Page -- http://www.php.net/manual/en/ref.network.php Edit -- https://master.php.net/note/edit/75922 Del: integrated -- https://master.php.net/note/delete/75922/integrated Del: useless -- https://master.php.net/note/delete/75922/useless Del: bad code -- https://master.php.net/note/delete/75922/bad+code Del: spam -- https://master.php.net/note/delete/75922/spam Del: non-english -- https://master.php.net/note/delete/75922/non-english Del: in docs -- https://master.php.net/note/delete/75922/in+docs Del: other reasons-- https://master.php.net/note/delete/75922 Reject -- https://master.php.net/note/reject/75922 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127868) next »