IP blocker script

  • lifeanatomy
  • Novice
  • Novice
  • lifeanatomy
  • Posts: 27
  • Loc: England!

Post 3+ Months Ago

any1 wrote:
BinaryTox1n wrote:
beh, if you know php you can have a php script do it for you, fairly easily too... i have a pre-written script that you can php-include on your page to block any number of ips you like... it uses a database to hold the ip adresses and displays a customized block message. (i know, i was bored, leave me alone lol) i can give it to you if you like, its fairly portable.


I've been looking for a script like that! I'd like to get it if you don't mind :wink:
Would it be possible to redirect visitors instead of displaying a blocking message?


read page 2!!!
  • any1
  • Born
  • Born
  • any1
  • Posts: 2

Post 3+ Months Ago

lifeanatomy wrote:

read page 2!!!


I did, and .htaccess option is not gonna work for me. I need php script, that's why I replied to that post.
  • dechev_1
  • Born
  • Born
  • dechev_1
  • Posts: 2
  • Loc: Bulgaria

Post 3+ Months Ago

SUPER:)
  • dechev_1
  • Born
  • Born
  • dechev_1
  • Posts: 2
  • Loc: Bulgaria

Post 3+ Months Ago

TO ADMIN
Hi,

I am a new member in your forum. I am happy, because I learned how I can block some people from my site:) Thanks you. I work with computers a lot. I like computers, computer programming and FLASH (make a professional design). I learned a lot of things from your FORUM and from you. I will be glad if we keep in touch.

Best wishes
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

I wrote an entire package to deal with blocking IPs and anonymous Proxies, problem is that you need to know a little PHP to use it.

Was very cool though, just include one file in your page and away you go!

http://www.ozzu.com/programming-forum/need-script-that-blocks-proxies-t26237-90.html
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

What can I say - it's a slow night.

This isn't anything like as full featured as Rabid Dog's - just define your ranges and, save it in a file and include it at the top of any page you want to deny to IP addresses.
PHP Code: [ Select ]
<?php
 
 
 
/**
 
 * Define the IP address range per octet
 
 * this example block any address from
 
 * 192.168.0.1 to 192.168.0.254
 
 */
 
$ranges[] = array(
 
   '192','192',
 
   '168','168',
 
   '0','255',
 
   '1','254'
 
);
 
 
 
/**
 
 * This one block the range 120.0.0.1 to 127.255.255.254
 
 */
 
$ranges[] = array(
 
   '127','127',
 
   '0','255',
 
   '0','255',
 
   '1','254'
 
);
 
 
 
/**
 
 * build the blocked range(s)
 
 */
 
foreach( $ranges as $range ){
 
   $rcount = 0;
 
   $vcount = 1;
 
   while( $rcount < 8 ){
 
      $p1 = ($rcount + 1);
 
      $varname = 'oct'.$vcount;
 
      if( $range[$rcount] == $range[$p1] ){
 
         $$varname = $range[$rcount];
 
      } else {
 
         $$varname = range($range[$rcount],$range[$p1]);
 
      }
 
      $vcount++;
 
      $rcount = ($rcount + 2);
 
   }
 
   
 
   /**
 
    * Grab the remote IP and break it into an array by octet
 
    */
 
   list($one,$two,$three,$four) = explode('.',$_SERVER['REMOTE_ADDR']);
 
   
 
   $test1 = $test2 = $test3 = $test4 = 0;
 
   
 
   $vars = array(
 
      'oct1' => 'one',
 
      'oct2' => 'two',
 
      'oct3' => 'three',
 
      'oct4' => 'four'
 
   );
 
   
 
   $testcount = 0;
 
   foreach( $vars as $oct => $num ){
 
      if( is_array($$oct) ){
 
         if( in_array($$num,$$oct) ){
 
            $testcount++;
 
         }
 
      } else {
 
         if( $$num == $$oct ){
 
            $testcount++;
 
         }
 
      }
 
   }
 
   
 
   if( $testcount > 3 ){
 
      // uncomment this to just display a message
 
      //die("You're not welcome here!");
 
     
 
      // redirect to google
 
      Header("Location: <!-- m --><span class="postlink">http://www.google.com</span><!-- m -->");
 
   }
 
}
 
?>
  1. <?php
  2.  
  3.  
  4.  
  5. /**
  6.  
  7.  * Define the IP address range per octet
  8.  
  9.  * this example block any address from
  10.  
  11.  * 192.168.0.1 to 192.168.0.254
  12.  
  13.  */
  14.  
  15. $ranges[] = array(
  16.  
  17.    '192','192',
  18.  
  19.    '168','168',
  20.  
  21.    '0','255',
  22.  
  23.    '1','254'
  24.  
  25. );
  26.  
  27.  
  28.  
  29. /**
  30.  
  31.  * This one block the range 120.0.0.1 to 127.255.255.254
  32.  
  33.  */
  34.  
  35. $ranges[] = array(
  36.  
  37.    '127','127',
  38.  
  39.    '0','255',
  40.  
  41.    '0','255',
  42.  
  43.    '1','254'
  44.  
  45. );
  46.  
  47.  
  48.  
  49. /**
  50.  
  51.  * build the blocked range(s)
  52.  
  53.  */
  54.  
  55. foreach( $ranges as $range ){
  56.  
  57.    $rcount = 0;
  58.  
  59.    $vcount = 1;
  60.  
  61.    while( $rcount < 8 ){
  62.  
  63.       $p1 = ($rcount + 1);
  64.  
  65.       $varname = 'oct'.$vcount;
  66.  
  67.       if( $range[$rcount] == $range[$p1] ){
  68.  
  69.          $$varname = $range[$rcount];
  70.  
  71.       } else {
  72.  
  73.          $$varname = range($range[$rcount],$range[$p1]);
  74.  
  75.       }
  76.  
  77.       $vcount++;
  78.  
  79.       $rcount = ($rcount + 2);
  80.  
  81.    }
  82.  
  83.    
  84.  
  85.    /**
  86.  
  87.     * Grab the remote IP and break it into an array by octet
  88.  
  89.     */
  90.  
  91.    list($one,$two,$three,$four) = explode('.',$_SERVER['REMOTE_ADDR']);
  92.  
  93.    
  94.  
  95.    $test1 = $test2 = $test3 = $test4 = 0;
  96.  
  97.    
  98.  
  99.    $vars = array(
  100.  
  101.       'oct1' => 'one',
  102.  
  103.       'oct2' => 'two',
  104.  
  105.       'oct3' => 'three',
  106.  
  107.       'oct4' => 'four'
  108.  
  109.    );
  110.  
  111.    
  112.  
  113.    $testcount = 0;
  114.  
  115.    foreach( $vars as $oct => $num ){
  116.  
  117.       if( is_array($$oct) ){
  118.  
  119.          if( in_array($$num,$$oct) ){
  120.  
  121.             $testcount++;
  122.  
  123.          }
  124.  
  125.       } else {
  126.  
  127.          if( $$num == $$oct ){
  128.  
  129.             $testcount++;
  130.  
  131.          }
  132.  
  133.       }
  134.  
  135.    }
  136.  
  137.    
  138.  
  139.    if( $testcount > 3 ){
  140.  
  141.       // uncomment this to just display a message
  142.  
  143.       //die("You're not welcome here!");
  144.  
  145.      
  146.  
  147.       // redirect to google
  148.  
  149.       Header("Location: <!-- m --><span class="postlink">http://www.google.com</span><!-- m -->");
  150.  
  151.    }
  152.  
  153. }
  154.  
  155. ?>
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Nice one this213 :)

But the first example would block ip range 192.168.0.1 to 192.168.255.254 wouldn't it?

Would it be okay if I used this theory in mine? That is one thing I don't cater for, blocking ranges.
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

Rabid Dog wrote:
But the first example would block ip range 192.168.0.1 to 192.168.255.254 wouldn't it?

Oops, you're right. I had changed that in the middle of playing with it and forgot to change the comment.

I hit this with the idea of blocking ranges from the beginning, since the poster stated the user he was trying to block someone on a dial up pool.

I don't care if you use it in your scripts - just remember me when you get famous from it :)

Since I have it now, I'll probably integrate it into php-nuke and oscommerce since I do quite a bit of work with both of those.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

thanks mate ;)

Post Information

  • Total Posts in this topic: 39 posts
  • Users browsing this forum: No registered users and 55 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.