Forum Moderators: open

Message Too Old, No Replies

htaccess regex syntax

         

mattie

2:18 pm on Dec 13, 2004 (gmt 0)

10+ Year Member



Hi, folks:

I'm beginning to block groups of ip addresses for a client, and want to make sure my regex syntax is correct.

Does this look correct:

SetEnvIf Remote_Addr "12\.166\.96\.[3-6][2-3]" bad_bot # 12.166.96.32-63
SetEnvIf Remote_Addr "61\.11\.230\.11[2-9]" bad_bot # 61.11.230.112-119
SetEnvIf Remote_Addr "62\.56\.2[3-4][5-8]" bad_bot # 62.56.235-248
SetEnvIf Remote_Addr "62\.173\.[3-6][2-3]" bad_bot # 62.173.32-63
SetEnvIf Remote_Addr "62\.193\.230\.1[6-9][0-1]" bad_bot # 62.193.160-191

Thanks,
Mattie

wilderness

8:02 pm on Dec 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Mattie,
I would suggest using Rewrites for this rather than sets.
Perhaps Jim or another may come along and provide some insght. I've just never used regex expressions like this in SET and not sure it works.

In the event that your currently do NOT have any active rewrites?
You'll need to begin with

RewriteEngine on

SetEnvIf Remote_Addr "12\.166\.96\.[3-6][2-3]" bad_bot # 12.166.96.32-63

RewriteCond %{REMOTE_ADDR} ^12\.166\.96\.(3[6-9]¦[45][0-9]¦6[23])$ [OR]

SetEnvIf Remote_Addr "61\.11\.230\.11[2-9]" bad_bot # 61.11.230.112-119

RewriteCond %{REMOTE_ADDR} ^61\.11\.230\.(11[2-9])$ [OR]

SetEnvIf Remote_Addr "62\.56\.2[3-4][5-8]" bad_bot # 62.56.235-248

RewriteCond %{REMOTE_ADDR} ^62\.56\.2(3[5-9]¦4[0-8])\. [OR]

SetEnvIf Remote_Addr "62\.173\.[3-6][2-3]" bad_bot # 62.173.32-63\.

RewriteCond %{REMOTE_ADDR} ^62\.173\.(3[2-9]¦[45][0-9]¦6[0-3])\. [OR]

SetEnvIf Remote_Addr "62\.193\.230\.1[6-9][0-1]" bad_bot # 62.193.160-191

RewriteCond %{REMOTE_ADDR} ^62\.193\.230\.1([6-8][0-9]¦9[01])$

Please note: I'm never able to recall the name of this thingt "¦" which the forum breaks apart. You will need to replace each incorrect thingy with the solid line.

Please note: in the event that this is the last range of your IP rewrites thn you omit the [OR]
prior to your closing action. 403, 403 deny page or whatever.

volatilegx

7:24 pm on Dec 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I'm never able to recall the name of this thingt "¦"

It's a "pipe symbol" :)

wilderness

10:37 pm on Dec 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It's a "pipe symbol"

it doesn't much help Dan.
No matter how times I see it?
It still doesn't stick.

Perhaps I need a bottle of Indian Ink and a needle ;)
Of course today they have shops on nearly every corner for piercings and tattoo's.

mattie

5:54 pm on Dec 15, 2004 (gmt 0)

10+ Year Member



I'd like to use the SetEnvIf Remote_Addr syntax as it works faithfully on the client's server.

What I'm trying to do is block IP address originating in Nigeria. I've looked on the blackholes.us site as well as another thread I've seen here with IP addresses listed.

Does anyone know how often the blackholes.us site is updated? I've surfed that site and haven't found this info (and the site owner hasn't responded to an eMail I sent him a few days ago).

Or is there another place where I can get this info online? Seems like someone should have made a database application we could get this info from.

wilderness

7:04 pm on Dec 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Or is there another place where I can get this info online

Some time back there was a mixing of open ranges in the ARIN block with non North American countries. Somebody sent me a link to the updates however I don't recall where I saved it.

This site at one time offered free break downs of all countries:
[networkinformation.com...]
That has changed.

It took some real poking around for me to find the site above when I did as I was unawre of precisely what I was looking for or what words to search on. I can only wish you or another best of luck.
My goal in finding these page was in separating the OCEANIC countries from the APNIC blocks. That process was completed some 18 months ago and Jim assisted in a rewrite solution to implement the Oceanic ranges into my htaccess file.

Surley the traffic you get from Nigeria is not so overwhelming that your unable to sort it out as it comes in?

Just look at the email properties when the spam comes in and grab the IP range, do a Whois and add that provider into your htaccess.
Actually if you only concern is spam, it's much easier just to use MailWasher or something similar.

Don

wilderness

7:12 pm on Dec 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'd like to use the SetEnvIf Remote_Addr syntax as it works faithfully on the client's server.

Just replace this portion of the lines I provided:

RewriteCond %{REMOTE_ADDR}

with your SetEnv beginning.

Don't forget to add your SetEnv line ending as well.
The numbers I provided work in Rewrites. As I previously, I have never used SetEnvIf Remote_Addr for regex numeracis.

I used straight numbers as provided in this page example, using "deny from"

[webmasterworld.com...]