php匹配ip段

//当前IP
$ip = '185.104.255.42'; 
//过滤的IP和IP段
$filter_ip = array(
'192.168.1.*',
'162.170.1.1',
'23.234.33.44'
);
$regexp = implode('|', str_replace( array('*','.'), array('\d+','\.') ,$filter_ip));
echo preg_match("/^(".$regexp .")$/", $ip);
点赞