#!/usr/bin/python # Merge malware domains with winhelp2002 hosts file import sys, urllib2 MALWARE_DOMAINS="http://www.malwaredomains.com/files/domains.txt" WINHELP_2002="http://www.mvps.org/winhelp2002/hosts.txt" def downloadResource(url): f = urllib2.urlopen(url) if f.getcode() == 200: lines = f.readlines() else: print "ERROR: Unexpected HTTP response code %d downloading %s" % (f.getcode(), url) sys.exit(1) f.close() return lines bad_domains = set() malware_domains = downloadResource(MALWARE_DOMAINS) winhelp_2002 = downloadResource(WINHELP_2002) for domain in filter(lambda x: not x.startswith('#'), malware_domains): bad_domains.add(domain.split('\t')[2]) for host in filter(lambda x: x.startswith('127.0.0.1'), winhelp_2002): bad_domains.add(host.split()[1]) for domain in bad_domains: print "127.0.0.1\t%s" % (domain,)