Over a million developers have joined DZone.

Build Blacklist .htaccess File Modified

DZone's Guide to

Build Blacklist .htaccess File Modified

· ·
Free Resource

#!/usr/bin/env python
# -*- coding: utf-8 -*-
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))
file('.htaccess', 'w').write('\n'.join(str))

Use of list to speed up.

Added prefix and suffix to make it a complete rewrite.

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}