How to Block a Range of IP Addresses

By  on  

As much as content creators want traffic to their website, there is such thing as the wrong type of traffic. Sometimes it's content scrapers, sometimes it's malicious bots; either way, it's important to know how to block problematic IPs from your site.

To block a range of IP addresses using an .htaccess file, you can use the * wildcard for pieces of the IP address:

Order Allow,Deny
Deny from 219.198.*.*
Allow from all

You can also use a regular expression:

RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^219\.198\.\.
RewriteRule ^ - [F]

Don't let known attackers and problematic bots bring your website to a halt! Be quick to check your site logs and ban addresses that are causing havoc!

Recent Features

  • By
    Conquering Impostor Syndrome

    Two years ago I documented my struggles with Imposter Syndrome and the response was immense.  I received messages of support and commiseration from new web developers, veteran engineers, and even persons of all experience levels in other professions.  I've even caught myself reading the post...

  • By
    Facebook Open Graph META Tags

    It's no secret that Facebook has become a major traffic driver for all types of websites.  Nowadays even large corporations steer consumers toward their Facebook pages instead of the corporate websites directly.  And of course there are Facebook "Like" and "Recommend" widgets on every website.  One...

Incredible Demos

  • By
    Add Styles to Console Statements

    I was recently checking out Google Plus because they implement some awesome effects.  I opened the console and same the following message: WARNING! Using this console may allow attackers to impersonate you and steal your information using an attack called Self-XSS. Do not enter or paste code that you...

  • By
    Smooth Scrolling with MooTools Fx.SmoothScroll

    I get quite a few support requests for my previous MooTools SmoothScroll article and the issue usually boils down to the fact that SmoothScroll has become Fx.SmoothScroll. Here's a simple usage of Fx.SmoothScroll. The HTML The only HTML requirement for Fx.SmoothScroll is that all named...

Discussion

  1. Jose Cerrejon

    Who is using Apache today? Just kidding. Do you know how to achieve the same using Nginx? Thanks in advance.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!