Several Methods for shielding ip list-PHP source code

Source: Internet
Author: User
Collect several common program processing methods for shielding ip Lists. Blocking some IP addresses can make your website better and more stable, next, we will not analyze the program processing methods for the following shielding and collecting several common blocked ip address lists. Blocking some IP addresses can make your website better and more stable, we will not analyze the blocking below.

Script ec (2); script

Below I have collected several commonList of blocked ip addressesTo make your website better and more stable, we will not analyze the following blocking 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; // if the ip address is not in the ip Format, false is returned.
$ 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; // if the ip address is not in the ip Format, false is returned.
$ 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; // it is not allowed if it is within the specified range.
If (stristr (",". $ str. ", *,") | stristr (",". $ str. ", *") return true; // if it appears for the first time ,*. or, * indicates that all sites are not allowed
$ Iplist = explode (",", $ str );
$ Ip = explode (".", $ ip );
For ($ I = 0; $ 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. * "; // The list of blocked ip addresses is separated by", ". If you want to shield all ip addresses, use * to shield 127. the ip address format starting with 127. *
$ Ip = "137.0.0.2"; // Ip address to be verified
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}. {$ }";
}
}
}
In this way, we can produce 255*255*255 large Ip address data volumes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.