Below I collect several commonly used shielding IP list of program processing method, shielding this can make your website better, more stable, below we do not analyze the following shielding method.
$ip _str = "127.0.0.1,192.1.1.*,202.*,127.*,123.*,142.*,*";
$ip = "127.0.0.254";
function Stopip ($IP, $ip _str)
{
if (strcmp (Long2ip (sprintf ('%u ', Ip2long ($IP)), $ip)) return false;//Verify IP if not IP format returns false
$ip = Explode (".", $ip);
if (eregi (, *,|,*.|,*) | (". $IP [0]. ". (". $ip [1]." | *).? (". $ip [2]." | *)?.? (". $ip [3]." | *) ",", ". $ip _str.", ")" return true;
}
if (Stopip ($ip, $ip _str)) echo 1;
function Stopip ($IP, $ip _str)
{
if (strcmp (Long2ip (sprintf ('%u ', Ip2long ($IP)), $ip)) return false;//Verify IP if not IP format returns false
$ip = Explode (".", $ip);
if (eregi (, *,|,*.|,*) |, (". $ip [0].". (". $ip [1]." | *).? (". $ip [2]." | *)?.? (". $ip [3]." | *),?) ",", ". $ip _str.", ")" return true;
}
function Stopip ($IP, $STR)
{
if (Stristr (",". $str. ",", $ip)) return true;//if it is not allowed in the range
if (Stristr (",". $str. ",", ", *,") | | stristr (",". $str. ",", ", *")) return true;//if the first appearance, *. Or, * means that all sites are not allowed
$iplist = Explode (",", $str);
$ip = Explode (".", $ip);
for ($i = 0; $i <count ($iplist); $i + +)
{
if (eregi ($ip [0].). (". $ip [1]." | *).? (". $ip [2]." | *)?.? (". $ip [3]." | *)? ", $iplist [$i]) return true;
}
}
Test
$ip _str = "127.0.0.1,192.1.1.*,202.*,127.*,123.*";//This is the screened IP list to "," separated, if you want to block all IP please use * If you want to block 127. The IP format at the beginning is 127.*
$ip = "137.0.0.2"; IP that needs to be validated
if (Stopip ($ip, $ip _str)) echo 1;
For ($i =1 $i <=255; $i + +)
{
For ($k =1 $k <=255; $K + +)
{
For ($a =1 $a <=255; $a + +)
{
$str. = "192. {$i}. {$k}. {$a} ";
}
}
}
This will produce a large amount of 255*255*255 IP data.