DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Build Blacklist .htaccess File

04.08.2005
| 7088 views |
  • submit to reddit
        I run 
./blacklist_builder.py > .htaccess 
 every week or so... 
 """
    blacklist_builder.py
    Get the entries from a blacklist
    and print them to standard output
    """
  
    latest = urllib2.urlopen("http://www.unknowngenius.com/blog/blacklist/")
    
     str = ''
    
     begin = "RewriteCond %{HTTP_REFERER} ^.*"
     for line in latest:
         str+= begin+ re.sub('(\s#:url:|\s#:regex-url:|\s#:rbl:)',
                                   ".*$ [OR]\n",line)
            
        return str

Output looks like this...
RewriteCond %{HTTP_REFERER} ^.*zpics.net.*$ [OR]
RewriteCond %{HTTP_REFERER} ^.*zt148.com.*$ [OR]
RewriteCond %{HTTP_REFERER} ^.*zum-bestpreis.de.*$ [OR]
RewriteCond %{HTTP_REFERER} ^.*zxyzxy.com.*$ [OR]
RewriteCond %{HTTP_REFERER} ^.*fondos-pantalla..*$ [OR]
RewriteCond %{HTTP_REFERER} ^.*.kucko.com.*$ [OR]
RewriteCond %{HTTP_REFERER} ^.*.gogof-ck.com.*$ [OR]

 .....