判斷IP是否在某個網段內


 

判斷IP是否在某個網段內

public function ip_in_network($ip, $network)
{
$ip = (double) (sprintf("%u", ip2long($ip)));
$s = explode('/', $network);
$network_start = (double) (sprintf("%u", ip2long($s[0])));
$network_len = pow(2, 32 - $s[1]);
$network_end = $network_start + $network_len - 1;

if ($ip >= $network_start && $ip <= $network_end)
{
return true;//本機ip屬於這個網段返回true
}
return false;//本機ip屬於這個網段返回false
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM