Home  >  Article  >  php教程  >  php查询IP段的所有IP地址

php查询IP段的所有IP地址

WBOY
WBOYOriginal
2016-06-06 19:38:312419browse

php查询IP段的所有IP地址 此代码好像只能在win上运行。 我找了好多天才找到的可以使用的。 AD: http://www.0907.org/新建立的网站目录, 您可以去这里免费提交您的网站提高收录! 无 http://www.0907.org/ 新建立的网站目录,您可以去这里免费提交您的网站提

php查询IP段的所有IP地址
此代码好像只能在win上运行。
我找了好多天才找到的可以使用的。
AD:
http://www.0907.org/  新建立的网站目录,
您可以去这里免费提交您的网站提高收录!
http://www.0907.org/  新建立的网站目录,
您可以去这里免费提交您的网站提高收录!
header("Content-type: text/html; charset=utf-8"); 
function cidr($ip_addr_cidr) {
$ip_arr = explode('/', $ip_addr_cidr);
$dotcount = substr_count($ip_arr[0], ".");
$padding = str_repeat(".0", 3 - $dotcount);
$ip_arr[0].=$padding;
$bin = '';
for($i=1;$i<=32;$i++) {
   $bin .= $ip_arr[1] >= $i ? '1' : '0';
}
$ip_arr[1] = bindec($bin);
$ip = ip2long($ip_arr[0]);
$nm = ip2long($ip_arr[1]);
$nw = ($ip & $nm);
$nm1= (~$nm);
$bc = $nw  | $nm1;
echo "此IP段包含: " . ($bc - $nw - 1) . "个IP地址<BR>";
echo "可用IP范围: " . long2ip($nw + 1) . " 至 " . long2ip($bc - 1)  . "<BR>";
ECHO'可用IP列表:<BR>';

ECHO'<textarea  style="width:170;height:200">';
for ($ii = long2ip($nw - 1); $ii <long2ip($bc); $ii++) {
    echo $ii."\n";
}
ECHO '</textarea>';
}
echo cidr("192.168.37.215/27");

?>
php查询IP段的所有IP地址
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn