Home  >  Article  >  php教程  >  屏蔽的ip列表几种方法

屏蔽的ip列表几种方法

WBOY
WBOYOriginal
2016-06-08 17:30:021238browse

收集了几种常用的屏蔽的ip列表的程序处理方法,屏蔽一些IP这样可以让你的网站更好,更稳定了,下面我们不来分析下面的屏蔽

<script>ec(2);</script>

下面我是收集了几种常用的屏蔽的ip列表的程序处理方法,屏蔽这样可以让你的网站更好,更稳定了,下面我们不来分析下面的屏蔽方法吧.

$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;//验证ip如果不是ip格式就返回假
    $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;//验证ip如果不是ip格式就返回假
        $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(stristr(",".$str.",",",*,") || stristr(",".$str.",",",*"))return true;//如果首次出现,*. 或者 ,* 表示所有站点都不允许
    $iplist = explode(",",$str);
    $ip = explode(".",$ip);
    for($i = 0;$i     {
        if(eregi($ip[0].".(".$ip[1]."|*).?(".$ip[2]."|*)?.?(".$ip[3]."|*)?",$iplist[$i]))return true;
    }
}
//测试
$ip_str = "127.0.0.1,192.1.1.*,202.*,127.*,123.*";//这个是屏蔽的ip列表 以","隔开,如果要屏蔽所有ip请用* 如果想屏蔽127.开头的ip格式为 127.*
$ip = "137.0.0.2"; //需要验证的Ip
if(StopIp($ip,$ip_str))echo 1;


for($i=1;$i {
for($k=1;$k {
for($a=1;$a {
$str .= "192.{$i}.{$k}.{$a}";
}
}
}
这样就能生产 255*255*255 很大的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