[Zope] newbie q: how to block IP

J Cameron Cooper jccooper@jcameroncooper.com
Wed, 12 Feb 2003 13:54:05 -0600


>
>
>Is this how I block an IP Adress?
>All I want is just to block or ban some IP Addresses
>to maybe a specific page or the whole website. 
>I know that with REQUEST[`REMOTE_ADDR`] you can find
>out one's ip address. but what i am looking is for a
>code or any function which allows me to block certain
>IP that I chose.
>
It's part of the way there. The quick-hack way to do it is to

1) put a list of banned IPs in a 'lines' property of the object you're 
blocking on.
2) wrap your content in a conditional check against those IPs. In Python 
something like

if REQUEST[`REMOTE_ADDR`] in blocked_ips:
    print "You are at a blocked address. Sorry."
else:
   print content

Similar for DTML (dtml-if) and Page Templates (tal:condition). You could 
do this for one page or stick it in a header for broader application.

If this doesn't scale too well, one could write a product to do it, say 
a 'RestrictedFolder' that would only allow call or traverse if the IP 
isn't banned.

If you want to block the whole site, you can use an outside proxy as 
previously mentioned.

          --jcc