Forum Moderators: open

Message Too Old, No Replies

Deny IP?

         

keyplyr

9:12 am on Feb 3, 2002 (gmt 0)

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



I wish to deny users (from 3 IPs) access to files in a directory. If this is done with an .htaccess file in that directory, how is the code written?

Thanks

keyplyr

10:22 am on Feb 3, 2002 (gmt 0)

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



Well, for lack of a better way, I am just listing the 3 IPs:

deny from xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx

(added question) Can I just use a partial IP?

deny from xxx.xxx.xxx

The first 3 sets of numbers are identical. In this way I hope to cover all variations from the same host.

justa

12:04 pm on Feb 3, 2002 (gmt 0)

10+ Year Member



Yes you can just list partial ip addresses which will eliminate all following.

I have the exact code I use but not on me, if you can wait 12 hours I'll be back with an answer when I get to work.

If you're running your own server you can actually add this to your httpd.conf file (assuming you're running apache).

<Directory "C:/Program Files/Apache Group/Apache/htdocs">
Order allow,deny
Allow from all
Deny from 155.205.
</Directory>

Ahhh, I can't remember if there is a wild card for the remaining. Sorry, will get back tomorrow if you haven't already sourced a solution.

keyplyr

6:34 pm on Feb 3, 2002 (gmt 0)

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



Thank you. I'm using virtual hosting at the present

Key_Master

7:06 pm on Feb 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make sure you do a host lookup on those IP's first. You don't want to inadvertently ban all of your AOL visitors.

[arin.net...]

keyplyr

7:37 pm on Feb 3, 2002 (gmt 0)

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



Thanks Key_Master. Actually, I just wish to deny them from one directory they are abusing (remote linking.) Arinwhois tells me the hosting block is:

209.240.192.0 - 209.240.223.255

Can this be written as?

deny from 209.240.192.0 - 209.240.223.255

Key_Master

8:06 pm on Feb 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can try it but I doubt it. My experience with virtual hosting is that they don't offer a whole lot of options with .htaccess files. Depending on the options your host server does allow, you might be able to ban by user agent, ISP, or possible even use wildcards. I would check with your hosting company and see what options they allow.

I know it's bulky but if all else fails, the following .htaccess file will ban only WebTV visitors and should work on 99% of UNIX servers:


<Limit GET POST>
order allow,deny
deny from 209.240.192.
deny from 209.240.193.
deny from 209.240.194.
deny from 209.240.195.
deny from 209.240.196.
deny from 209.240.197.
deny from 209.240.198.
deny from 209.240.199.
deny from 209.240.200.
deny from 209.240.201.
deny from 209.240.202.
deny from 209.240.203.
deny from 209.240.204.
deny from 209.240.205.
deny from 209.240.206.
deny from 209.240.207.
deny from 209.240.208.
deny from 209.240.209.
deny from 209.240.210.
deny from 209.240.211.
deny from 209.240.212.
deny from 209.240.213.
deny from 209.240.214.
deny from 209.240.215.
deny from 209.240.216.
deny from 209.240.217.
deny from 209.240.218.
deny from 209.240.219.
deny from 209.240.220.
deny from 209.240.221.
deny from 209.240.222.
deny from 209.240.223.
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
<Files ~ "\.htaccess$">
order deny,allow
deny from all
</Files>

keyplyr

8:13 pm on Feb 3, 2002 (gmt 0)

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



terrific - what's the line "<Limit GET POST>" do?

Key_Master

8:26 pm on Feb 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It basically means that the WebTV IP is prohibited or "limited" from "getting" or "posting" to any page or script on your site.

The following bit of code prevents anyone from viewing your .htaccess file:

<Files ~ "\.htaccess$">
order deny,allow
deny from all
</Files>

Since you are only preventing access to a specific directory, try loading the .htaccess file to that directory instead of the root directory.

keyplyr

8:58 pm on Feb 3, 2002 (gmt 0)

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



>Since you are only preventing access to a specific directory, try loading the .htaccess file to that directory instead of the root directory.

Yes, that's what I had done thank you Key_Master. I wish the WTV users to enjoy the website but they have run up bandwidth bills for me numerous times by remote linking to my audio files in their email and newsgroup posts, despite countless polite requests not to and WTV management does a great Pontius Pilot impression.

I have employed various rewrite techniques to stop the remote linking (other group users do it as well) but since the WindowsMedia Play list imports the entire path of the audio files, instead of copying it, these rewrites basically stop too many inocent users from enjoying the music.

This drastic measure to ban WTV users from accessing the files even on-site is my last resort to save on server bills. Thanks again.

Marcia

9:08 pm on Feb 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm having constant remote linking to graphics, some of which get a lot of usage. Apparently some work well as backgrounds behind message boards, those are the worst. I need to keep out users from certain entire sites as I catch them, they load the logs up, are easy to catch right way.

Is that done the same way?

keyplyr

10:04 pm on Feb 3, 2002 (gmt 0)

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



Marcia try this .htaccess file in your images directory:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://yourdomain/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.yourdomain/.*$ [NC]
RewriteRule .*\.gif$ - [G]

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://yourdomain/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.yourdomain/.*$ [NC]
RewriteRule .*\.jpg$ - [G]