Over a million developers have joined DZone.

Build Blacklist .htaccess File Modified

·

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
blacklist_builder.py
Get the entries from a blacklist
and print them to standard output
"""
import urllib2, re
latest = urllib2.urlopen("http://www.unknowngenius.com/blog/blacklist/")
prefix = 'RewriteEngine  on'
suffix = 'RewriteRule /(.*) / [F,L]'
str = [prefix]
begin = "RewriteCond %{HTTP_REFERER} ^.*"
for line in latest:
	print '.',
	str.append(begin + re.sub('(\s#:url:|\s#:regex-url:|\s#:rbl:)', ".*$ [OR,NC]", line))
str.append(suffix)
file('.htaccess', 'w').write('\n'.join(str))



Use of list to speed up.

Added prefix and suffix to make it a complete rewrite.
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}