note 119478 added to ref.network
| From: | Anonymous | Date: | Thu, 16 Jun 2016 17:15:55 +0000 |
| Subject: | note 119478 added to ref.network | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205735@lists.php.net to get a copy of this message | ||
improved version of philippe-at-cyberabuse.org's answer:
<?php
function cidrconv($net) {
$start = strtok($net,"/");
$n = 3 - substr_count($net, ".");
if ($n > 0)
{
for ($i = $n;$i > 0; $i--)
$start .= ".0";
}
$bits1 = str_pad(decbin(ip2long($start)), 32, "0", STR_PAD_LEFT);
$net = (1 << (32 - substr(strstr($net, "/"), 1))) - 1;
$bits2 = str_pad(decbin($net), 32, "0", STR_PAD_LEFT);
$final = "";
for ($i = 0; $i < 32; $i++)
{
if ($bits1[$i] == $bits2[$i]) $final .= $bits1[$i];
if ($bits1[$i] == 1 and $bits2[$i] == 0) $final .= $bits1[$i];
if ($bits1[$i] == 0 and $bits2[$i] == 1) $final .= $bits2[$i];
}
return array($start, long2ip(bindec($final)));
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 2001:610:600:8925:2556:7bd4:20e7:f74d
----
Manual Page -- http://php.net/manual/en/ref.network.php
Edit -- https://master.php.net/note/edit/119478
Del: integrated -- https://master.php.net/note/delete/119478/integrated
Del: useless -- https://master.php.net/note/delete/119478/useless
Del: bad code -- https://master.php.net/note/delete/119478/bad+code
Del: spam -- https://master.php.net/note/delete/119478/spam
Del: non-english -- https://master.php.net/note/delete/119478/non-english
Del: in docs -- https://master.php.net/note/delete/119478/in+docs
Del: other reasons-- https://master.php.net/note/delete/119478
Reject -- https://master.php.net/note/reject/119478
Search -- https://master.php.net/manage/user-notes.php