Skip to content

Instantly share code, notes, and snippets.

@mgilank
Created October 29, 2021 11:41
Show Gist options
  • Save mgilank/dbab003942ebe84911555fa44d7106a2 to your computer and use it in GitHub Desktop.
Save mgilank/dbab003942ebe84911555fa44d7106a2 to your computer and use it in GitHub Desktop.
tearing ipv4
<?php
echo "input : 103.10.145.3/24 <br>";
function cidrToRange($cidr) {
$range = array();
$cidr = explode('/', $cidr);
$range[0] = long2ip((ip2long($cidr[0])) & ((-1 << (32 - (int)$cidr[1]))));
$range[1] = long2ip((ip2long($range[0])) + pow(2, (32 - (int)$cidr[1])) - 1);
return $range;
}
var_dump(cidrToRange("103.10.145.3/24"));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment