Mar 7, 2009
admin

Block IP addresses Using .HTACCESS

Hello Friends !!

In my previous post, i was write how to block IP address using PHP script ?

Today i will write that how to block IP address using .HTACCESS ?

There are several ways to block a specific IP range.

The first utilizes a CIDR number to block the specified range (via htaccess):

# block IP range by CIDR number
<Limit GET POST PUT>
order allow,deny
allow from all
deny from 214.53.25.64/26
</Limit>


The second method is similar, only here we are expressing the range in netmask notation, using corresponding network/netmask values:

# block an IP range via network/netmask values
<Limit GET POST PUT>
order allow,deny
allow from all
deny from 214.53.25.64/255.255.255.192
</Limit>

The third method tests all IP addresses against a predefined regular expression via RewriteCond/RewriteRule directives:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^214\.53\.25\.(6[4-9]|7[0-9]|8[0-9]|9[0-9])$ [OR]
RewriteCond %{REMOTE_ADDR} ^214\.53\.25\.1([0-1][0-9]|2[0-8])$
RewriteRule .* – [F]

Here is a way of blocking a specific ISP via its IP address(es).

<Files *>
Order Allow,Deny
Allow from all
Deny from 123.123.123.
Deny from 456.456.456.
</Files>

There is probably a more efficient way to write the regular expressions in the previous example, but that should definitely get the job done.

I think this post become useful to you.

  • http://www.mavenmullet.com/ srganesan

    HI

    this tutorial is very help ful for me thanks :D

  • http://www.mavenmullet.com srganesan

    HI

    this tutorial is very help ful for me thanks :D

  • http://JoshuaXiong.Webs.Com/ JoshuaXiong

    HI

  • http://JoshuaXiong.Webs.Com JoshuaXiong

    HI

  • http://www.jaceju.net/blog/?p=410 網站製作學習誌 » [Web] 連結分享

    [...] Block IP addresses Using .HTACCESS [...]

  • http://tagz.in/posts/7cw/comments/ Tagz | "Block IP addresses Using .HTACCESS | php genious" | Comments

    [...] [upmod] [downmod] Block IP addresses Using .HTACCESS | php genious (phpgenious.com) 1 points posted 2 months, 1 week ago by SixSixSix tags webdesign imported [...]

  • GarrySch

    Someone help me, please. I am not able to get my .htaccess file to work. It crashes the site. I know my problem lies with the syntax prior to the .

    Thanx.

    Garry
    garrysch@swbell.net

  • GarrySch

    Someone help me, please. I am not able to get my .htaccess file to work. It crashes the site. I know my problem lies with the syntax prior to the .

    Thanx.

    Garry
    garrysch@swbell.net

  • Guest

    how can i block a ip range like this
    5.8.12.0.0 — 5.8.255.255

  • phpgenious

    5.8.12.0.0 ? Is it right address ? Please provide right address range .

Support to grow

If you think my post is helps you then please make donation and do support to grow:

PHP Genious Services

I am a PHP freelancer india, PHP Developer india, PHP programmer india, Wordpress Freelancer india, Wordpress customization services, Wordpress Plugin Developer, Wordpress theme customization, Wordpress plugin customization, Magento Freelancer, Magento Developer india, Magento customization services, Magento theme integration, Opencart Developer india, Zencart Freelancer, Opencart customization, Opencart plugin development, HTML and CSS customization, cakePHP Developer, cakePHP Freelancer india, Ecommerce Developer india

Click Here for

Follow me on Facebook

Categories

Get Adobe Flash playerPlugin by wpburn.com wordpress themes