PHP Script – IP Banned




Tagged Under : , , , ,

Version: 13.2
Revision: 39 Build 16

PHP Script – IP Banned

Introduction:
last night, I was repairing my “HTA” files, it was a little messed up, so I have to re-write parts of the codes and scribble it down into smaller bits. However, it was boring as hell!

Here is my little “IP-Ban.php” script. I designed this script from scratch. But, I don’t know if I want to use it.
Don’t get me wrong…I did test the script, It works…

1.] Download notepad++ from the original author or from a mirror and install the software.
——————————-

http://sourceforge.net/projects/notepad-plus/

http://filehippo.com/download_notepad/

——————————-

2.] Copy this “PHP Script” and save it as a “ban-ip.php” extension.

3.] Select one of these “IP script” and replace the default IP address with your own address.
After that, just add this “include” string, straight into your wordpress files.

—Copy Source Code—

<?php
include("ip-ban.php");
?>

—End Source Code—

Special Notice: by following the rules and regulations, these scripts was created / written by me from scratch. They are also revised for stability and bugs free. However, please use these script at your own risk!

Method One – Blacklist Host Style
—Copy Source Code—

<?php
$blackList = array();
$blackList[] = "192.168.1.1";
$blackList[] = "192.168.2.*";

if(in_array($_SERVER['REMOTE_ADDR'], $blackList))  {
	die("You have been banned!");
}  else  {
	foreach($blackList as $blackIP) {
		if(eregi($blackIP,$_SERVER['REMOTE_ADDR']))  {
			die("You have been banned!"); 	}
	}
} ?>

—End Source Code—

Method Two – Blacklist Simplified Style
—Copy Source Code—

<?php $banned = array (
//Add your own IP address under this line
'122.2.13.1',
'144.2.76.6',
'166.2.76.6',
// IP Address Ends Here
);
$ip = GetHostByName($REMOTE_ADDR);
if (in_array($ip,$banned)
{
echo 'You are banned from this site!';
exit();
} ?>

—End Source Code—

Method Three – Blacklist Intermediate Style
—Copy Source Code—

<?php
// IP in the form of "127.0.0.1" in a host form
$banned[0]="xxx.xxx.xxx.xxx";
$banned[1]="xxx.xxx.xxx.xxx";
$banned[2]="xxx.xxx.xxx.xxx";
// Ban IPs Ends

if (in_array($_SERVER['REMOTE_ADDR'],$banned))
{
header("location: http://www.google.com/");
exit();
} ?>

—End Source Code—

Method Four – Blacklist Text File

Notes: make a text file in the same folder, and give it permmission: 755.
—Copy Source Code—

<?php
error_reporting(0);
// Look for the "ip-ban.txt" and replace it with your file.
// The files contains IP addresses.
if ($handle = fopen("ip-ban.txt", "r+")) {
    $ip = explode("
", fread($handle, filesize("ip-ban.txt")));
    for ($i = 0; $i < count($ip); $i++) {
        $ip[$i] = str_replace("*", "(.*)", $ip[$i]);
// Change the link here. But, don't remove "Location" from the header!
        if (ereg($ip[$i], $_SERVER['REMOTE_ADDR'])) {
            header("Location: http://google.com/");
        }
    } fclose($handle);
} ?>

—End Source Code—

Method Five – Blacklist & Redirection
—Copy Source Code—

<?php
$block_ips = array("000.000.000.000", "000.000.000.000");
$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
foreach ($block_ips as $block_ip) {
if ($ip == $block_ip) {
die(header("Location: anypage.php"));
	}
} ?>

—End Source Code—

Method Six – Blacklist portable v3
—Copy Source Code—

<?php
$deny = array(
// Add your offending IP adress here
"111.111.111",
"222.222.222",
"333.333.333"
);
if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
   header("location: http://www.google.com/");
   exit();
} ?>

—End Source Code—

Method Seven – Blacklist Multifunctional
—Copy Source Code—

<?php
// Denied IP's.
//Comment these lines if you're using "$deny_ips = file".
$deny_ips = array(
        '209.240.206.199',
        '209.240.206.200',
        '209.240.206.201',
        '209.240.206.202',
    );

// Create a txt file and use instead.
//Remove the comments bellow this line.
// $deny_ips = file('blocked_ips.txt');

// read user ip address:
$ip = isset($_SERVER['REMOTE_ADDR']) ? trim($_SERVER['REMOTE_ADDR']) : '';

// search current IP in $deny_ips array
if (($i = array_search($ip, $deny_ips)) !== FALSE){

// user is blocked:
echo "Your IP address ('$ip') was blocked!";
exit;
}

// End of Blocking

?>

—End Source Code—

Method Eight – Blacklist Multifunctional v2
—Copy Source Code—

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$ipArray = preg_replace("#\r\n?|\n#","",file('IP-Ban.txt'));  // read the file into an array
foreach ($ipArray as $ipTest) {
  if (substr_count($ip, $ipTest) != "0") {
    die(header("Location: anypage.php"));
  }
} ?>

—End Source Code—

4.] Finally, you’ll need to upload one of these files and use the codes to import this script.

5.] Done!

Copyrighted By Lair360




Blocking spammers and referrers




Tagged Under : , , , ,

Version: 13.2
Revision: 44 Build 66

Blocking spammers and referrers

Introduction:
on the 20th of March, my website was hit by a bunch of clicking robots!
So, I decided to kick them them out of my website and block them from eating my bandwidth.
These traffic are fake and they are doing this to ruin my website and destroy my services for real people and genuine referrals!

1.] Download notepad++ from the original author or from another source.
——————————-

http://sourceforge.net/projects/notepad-plus/

http://filehippo.com/download_notepad/

——————————-

2.] Copy one of these script and save it as a “.htaccess” file.
After that, you will need to delete your old files, which is from your server, then upload your updated version.

Block traffic from a single referrer.
—Copy Source Code—

RewriteEngine On
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} ^http://(www\.)?badsite\.net/ [NC]
RewriteRule .* - [F]

—End Source Code—

Block traffic from multiple referrers.
—Copy Source Code—

RewriteEngine On
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} ^http://(www\.)?badsite\.net/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?badsite\.com/ [NC]
RewriteRule .* - [F]

—End Source Code—

Blocking all domains and referrers
—Copy Source Code—

RewriteEngine On
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com/ [NC]
RewriteCond %{HTTP_REFERER} ^http:// [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)? [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule \.* - [F]

—End Source Code—

Blocking specific domains by file formats.
—Copy Source Code—

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(www\.)?badsite\.net/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?badsite\.com/ [NC]
RewriteRule \.(jpe?g|gif|png|zip|rar)$ - [F]

—End Source Code—

Blocking a primary domain + subdomains.
—Copy Source Code—

## SITE REFERRER BANNING
RewriteEngine On
# Options +FollowSymlinks

RewriteCond %{HTTP_REFERER} badsite\.com [NC,OR]
RewriteCond %{HTTP_REFERER} sub1\.badsite\.net [NC,OR]
RewriteCond %{HTTP_REFERER} sub2\.badsite\.com [NC]
RewriteRule .* - [F]

—End Source Code—

Denies referrals from specific domain names.
—Copy Source Code—

RewriteEngine On
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} ^(http://)?(www\.)?badsite.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^(http://)?(www\.)?badsite.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^(http://)?(www\.)?badsite.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^(http://)?(www\.)?badsite.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^(http://)?(www\.)?badsite.*$ [NC]
RewriteRule .* - [F,L]

—End Source Code—

Denies referrals by file format filtering.
—Copy Source Code—

RewriteEngine On
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain1\.com.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain2\.co\.uk.*$ [NC]
RewriteRule \.(jpg|jpeg|png|gif|zip|rar)$ - [F,L]

—End Source Code—

Copyrighted by Lair360




Restrict certain hosts or IP address




Tagged Under : , , ,

Version: 12.4
Revision: 45 Build 68

Restrict certain hosts or IP address

Introduction: this tutorial will help user to block bad hosts and IP address from tampering your website. On the other hand, you will need to be careful with your .htaccess file – configurations; if you set one of the commands by mistake, your browser will generate a blank page with an Error 404 or 500.

1.] Download notepad++ from the original author or from a mirror and install the software.

——————————-

http://sourceforge.net/projects/notepad-plus/

http://filehippo.com/download_notepad/

——————————-

2.] Copy this code to your notepad and save the source code as “.htaccess”.

This source code is use to block everyone and it will only allow certain host / IP address to access.

Warning: you must be careful and test your htaccess file in a sub folder.
A slight mistake will also block you and your entire website!

Notes: Limit Get Post is defined as…
- limit the IP ban (users) to GET requests and POST actions.

—Copy Source Code—

<Limit GET POST>
order deny,allow
deny from all
allow from 199.166.210.55
allow from 199.166.120.22
allow from allowdomain1.net
allow from allowdomain2.net
allow from allowdomain3.net
</Limit>

—End Source Code—

This source code is a little different. But, it will allow everyone and it will only block certain host / IP address to access.

—Copy Source Code—

<Limit GET POST>
order allow,deny
allow from all
deny from 199.166.210.55
deny from 199.166.120.22
deny from denydomain1.net
deny from denydomain2.net
deny from denydomain3.net
</Limit>

—End Source Code—

This source code is the same and it also performs the same job…

Notes: Limit Get is defined as…
- limit the IP ban (users) to GET requests.

—Copy Source Code—

<Limit GET>
order deny,allow
deny from 63.135.80.49
deny from 208.75.184.192
deny from denydomain1.net
deny from denydomain2.net
deny from denydomain3.net
allow from all
</LIMIT>

—End Source Code—

This source code is the same as the above. But, it blocks everyone and allows certain host / IP address to access.

—Copy Source Code—

<Limit GET>
order allow,deny
allow from 63.135.80.49
allow from 208.75.184.192
allow from allowdomain1.net
allow from allowdomain2.net
allow from allowdomain3.net
deny from all
</LIMIT>

—End Source Code—

This source will also do the trick. However, it’s a little more strict…

—Copy Source Code—

<Limit GET HEAD POST>
order deny,allow
deny from 128.42
deny from 192.136.146
deny from 192.136.153
deny from 192.225.19
deny from denydomain1.net
allow from all
</LIMIT>

—End Source Code—

To block users from looking at your htaccess files, you can use this source code…

—Copy Source Code—

<Files .htaccess>
order allow,deny
deny from all
</Files>

—End Source Code—
Copyrighted by Lair360