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.

You can leave a response, or trackback from your own site.

View Comments to “Block IP addresses Using .HTACCESS”

  1. srganesan says:

    HI

    this tutorial is very help ful for me thanks :D

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

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

  4. GarrySch says:

    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

  5. Guest says:

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

  6. phpgenious says:

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

Leave a Reply

blog comments powered by Disqus
Subscribe to RSS Feed Follow me on Twitter!
Get Adobe Flash playerPlugin by wpburn.com wordpress themes
Thank you for using IGIT Tweet Share Button, a plugin by HackingEthics