/** * 判断IP是否在某个网络内 * @param $ip 192.168.0.128 * @param $network 192.168.0.1/24 * @return bool */ function ip_in_network($ip, $network) { $ip = (double) (sprintf("%u", ip2long($ip))); $s = explode('/', $network); // p($s);die; $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; } return false; }