function make32s($ip) { if (strpos($ip, "-")) { $ip = IPTools::breakrange($ip); } elseif (strpos($ip, "/")) { $ip_info = IPTools::cidrinfo($ip); $range = $ip_info['RANGE_START'] . "-" . $ip_info['RANGE_END']; $ip = IPTools::breakrange($range); } else { $ip = $ip; } return $ip; }
<?php /** * This example will display information about a cidr block * * You can pass along a full cidr nottaion such as "192.168.1.0/24", or a shorthand notation like "10/8" */ require "../IPTools.class.php"; // This example shows you can pass along a full cidr notation and we will see the results $cidr1 = "192.168.1.0/24"; echo "{$cidr1}\n"; $ips = IPTools::cidrinfo($cidr1); print_r($ips); $cidr2 = "10/8"; echo "{$cidr2}\n"; $ips = IPTools::cidrinfo($cidr2); print_r($ips);
<?php require "../IPTools.class.php"; $range = "192.168.1.1-192.168.1.10"; $ips = IPTools::breakrange($range); print_r($ips);
/** * @dataProvider ipMatchProvideInvalid */ public function testIpNotMatched($ip, $range) { $this->assertFalse($this->instance->ipMatch($ip, $range), "{$ip} should not match with {$range}"); }