#!/usr/bin/python #simple tor ip collector and blocker v. 2 #made by:ev1lut10n import urllib,sys,os,sgmllib def get_daftar_tor(): os.system("rm -f Tor_ip_list_ALL.csv;wget http://torstatus.blutmagie.de/ip_list_all.php/Tor_ip_list_ALL.csv") file = open("Tor_ip_list_ALL.csv") while 1: tor_ip = file.readline() tor_ip=tor_ip.rstrip() cmd="/sbin/iptables -A INPUT -s "+tor_ip+" -j DROP" print cmd+" ---> executed" os.system(cmd) if not tor_ip: break def fetch_from_site_also(): whois="/cgi-bin/whois.pl?ip=" site="http://torstatus.blutmagie.de" try: site_data = urllib.urlopen(site) parser = MyParser() parser.parse(site_data.read()) except(IOError),msg: print "Error in connecting site ", site print msg sys.exit(1) links = parser.get_hyperlinks() for l in links: if whois in l: ip_of_t0r= l.replace("/cgi-bin/whois.pl?ip=","") ip_of_t0r=ip_of_t0r.rstrip() print ip_of_t0r cmd="/sbin/iptables -A INPUT -s "+ip_of_t0r+" -j DROP" print cmd+" ---> executed" os.system(cmd) #asit dhal myparser class class MyParser(sgmllib.SGMLParser): "A simple parser class." def parse(self, s): "Parse the given string 's'." self.feed(s) self.close() def __init__(self, verbose=0): "Initialise an object, passing 'verbose' to the superclass." sgmllib.SGMLParser.__init__(self, verbose) self.hyperlinks = [] def start_a(self, attributes): "Process a hyperlink and its 'attributes'." for name, value in attributes: if name == "href": self.hyperlinks.append(value) if name == "src": self.hyperlinks.append(value) def get_hyperlinks(self): "Return the list of hyperlinks." return self.hyperlinks os.system("service iptables start") get_daftar_tor() fetch_from_site_also() os.system("service iptables save")