diff --git a/includes/misc.py b/includes/misc.py index 7d1a91d..b9c7ec7 100644 --- a/includes/misc.py +++ b/includes/misc.py @@ -7,12 +7,12 @@ import rocksock """ return formatted timestamp """ def timestamp(): - return time.strftime('%H:%M:%S', time.gmtime()) + return time.strftime('%H:%M:%S', time.gmtime()) """ return some random string """ def random_string(strlen=20): - return ''.join([random.choice(string.letters) for x in xrange(strlen)]) + return ''.join([random.choice(string.letters) for x in xrange(strlen)]) def _log(strng, level='info'): - print '%s/%s\t%s' % (timestamp(), level, strng) + print '%s/%s\t%s' % (timestamp(), level, strng) diff --git a/includes/mysqlite.py b/includes/mysqlite.py index 340f94c..bd9fdb2 100644 --- a/includes/mysqlite.py +++ b/includes/mysqlite.py @@ -3,31 +3,31 @@ import sqlite3 as lite class mysqlite: - def execute(self, query, args = None, rmin = 1.5, rmax = 7.0): + def execute(self, query, args = None, rmin = 1.5, rmax = 7.0): - while True: - try: return self.cursor.execute(query,args) if args else self.cursor.execute(query) - except: - print '%s\nquery: %s\nargs: %s' % (str(sys.exc_info()), str(query), str(args)) - time.sleep(random.uniform(rmin, rmax)) + while True: + try: return self.cursor.execute(query,args) if args else self.cursor.execute(query) + except: + print '%s\nquery: %s\nargs: %s' % (str(sys.exc_info()), str(query), str(args)) + time.sleep(random.uniform(rmin, rmax)) - def executemany(self, query, args, rmin = 1.5, rmax = 7.0): + def executemany(self, query, args, rmin = 1.5, rmax = 7.0): - while True: - try: return self.cursor.executemany(query,args) - except: - print '%s\nquery: %s\nargs: %s' % (str(sys.exc_info()), str(query), str(args)) - time.sleep(random.uniform(rmin, rmax)) + while True: + try: return self.cursor.executemany(query,args) + except: + print '%s\nquery: %s\nargs: %s' % (str(sys.exc_info()), str(query), str(args)) + time.sleep(random.uniform(rmin, rmax)) - def commit(self, rmin = 1.5, rmax = 7.0): - while True: - try: return self.handle.commit() - except: time.sleep(random.uniform(rmin, rmax)) + def commit(self, rmin = 1.5, rmax = 7.0): + while True: + try: return self.handle.commit() + except: time.sleep(random.uniform(rmin, rmax)) - def close(self): - self.handle.close() + def close(self): + self.handle.close() - def __init__(self, database, factory = None): - self.handle = lite.connect(database) - if factory: self.handle.text_factory = factory - self.cursor = self.handle.cursor() + def __init__(self, database, factory = None): + self.handle = lite.connect(database) + if factory: self.handle.text_factory = factory + self.cursor = self.handle.cursor() diff --git a/includes/proxywatchd.py b/includes/proxywatchd.py index 92f45e2..3987bd6 100644 --- a/includes/proxywatchd.py +++ b/includes/proxywatchd.py @@ -15,145 +15,145 @@ import rocksock class Proxywatchd(Thread): - def stop(self): - _log('Requesting proxywatchd to halt (%d thread(s))' % len([item for item in self.threads if item.isAlive()])) - self.running = 0 + def stop(self): + _log('Requesting proxywatchd to halt (%d thread(s))' % len([item for item in self.threads if item.isAlive()])) + self.running = 0 - def __init__(self, config_file): - Thread.__init__(self) + def __init__(self, config_file): + Thread.__init__(self) - self.threads = [] - self.running = 1 - self.parser = SafeConfigParser() - self.parser.read(config_file) + self.threads = [] + self.running = 1 + self.parser = SafeConfigParser() + self.parser.read(config_file) - self.maxfail = self.parser.getint('global', 'proxy_max_fail') - self.maxthreads = self.parser.getint('watcherd', 'threads') - self.checktime = self.parser.getint('watcherd', 'checktime') - self.timeout = self.parser.getint('watcherd', 'timeout') - self.database = self.parser.get('global', 'database') - self.torhosts = [ str(i).strip() for i in self.parser.get('global', 'tor_host').split(',') ] - self.read_timeout = self.parser.getint('watcherd', 'read_timeout') + self.maxfail = self.parser.getint('global', 'proxy_max_fail') + self.maxthreads = self.parser.getint('watcherd', 'threads') + self.checktime = self.parser.getint('watcherd', 'checktime') + self.timeout = self.parser.getint('watcherd', 'timeout') + self.database = self.parser.get('global', 'database') + self.torhosts = [ str(i).strip() for i in self.parser.get('global', 'tor_host').split(',') ] + self.read_timeout = self.parser.getint('watcherd', 'read_timeout') - # create table if needed - self.mysqlite = mysqlite.mysqlite(self.database, str) - self.mysqlite.execute('CREATE TABLE IF NOT EXISTS proxylist (proxy BLOB, country BLOB, added INT, failed INT, tested INT, source BLOB, dronebl INT, proto TEXT, duration INT)') - self.mysqlite.commit() - self.echoise = time.time() - 3600; - self.ticks = time.time() - 3600; + # create table if needed + self.mysqlite = mysqlite.mysqlite(self.database, str) + self.mysqlite.execute('CREATE TABLE IF NOT EXISTS proxylist (proxy BLOB, country BLOB, added INT, failed INT, tested INT, source BLOB, dronebl INT, proto TEXT, duration INT)') + self.mysqlite.commit() + self.echoise = time.time() - 3600; + self.ticks = time.time() - 3600; - with open('servers.txt', 'r') as handle: self.servers = handle.read().split('\n') + with open('servers.txt', 'r') as handle: self.servers = handle.read().split('\n') - self.start() + self.start() - def run(self): - _log('Starting proxywatchd..', 'notice') + def run(self): + _log('Starting proxywatchd..', 'notice') - threads = [] - self.mysqlite = mysqlite.mysqlite(self.database, str) + threads = [] + self.mysqlite = mysqlite.mysqlite(self.database, str) - while self.running: + while self.running: - if len(threads) < self.maxthreads: - t = threading.Thread(target=self.daemon, args=(self.servers,)) - t.start() - threads.append(t) - time.sleep( random.choice( xrange(1,3))) + if len(threads) < self.maxthreads: + t = threading.Thread(target=self.daemon, args=(self.servers,)) + t.start() + threads.append(t) + time.sleep( random.choice( xrange(1,3))) - else: time.sleep(1) + else: time.sleep(1) - if (time.time() - self.echoise) >= 180: - _log('Proxywatchd threads: %d/%d' % (len(threads), self.maxthreads)) - self.echoise = time.time() + if (time.time() - self.echoise) >= 180: + _log('Proxywatchd threads: %d/%d' % (len(threads), self.maxthreads)) + self.echoise = time.time() - self.mysqlite.close() + self.mysqlite.close() - def is_drone_bl(self, proxy): - p = proxy.split(':')[0] - proxies = {'http':'socks4://%s:%s@%s' % (p,p,random.choice(self.torhosts))} - resp = requests.get('http://dronebl.org/lookup?ip=%s' % p, proxies=proxies) - if 'No incidents regarding' in resp.text: return 0 - else: return 1 + def is_drone_bl(self, proxy): + p = proxy.split(':')[0] + proxies = {'http':'socks4://%s:%s@%s' % (p,p,random.choice(self.torhosts))} + resp = requests.get('http://dronebl.org/lookup?ip=%s' % p, proxies=proxies) + if 'No incidents regarding' in resp.text: return 0 + else: return 1 - def connect_socket(self, proxy, servers, proto = None): - protos = ['http', 'socks5', 'socks4'] + def connect_socket(self, proxy, servers, proto = None): + protos = ['http', 'socks5', 'socks4'] - for proto in protos: - torhost = random.choice(self.torhosts) - duration = time.time() - proxies = [ rocksock.RocksockProxyFromURL('socks4://%s' % torhost), - rocksock.RocksockProxyFromURL('%s://%s' % (proto, proxy[0])), - ] + for proto in protos: + torhost = random.choice(self.torhosts) + duration = time.time() + proxies = [ rocksock.RocksockProxyFromURL('socks4://%s' % torhost), + rocksock.RocksockProxyFromURL('%s://%s' % (proto, proxy[0])), + ] - srv = random.choice(servers).strip() - try: - sock = rocksock.Rocksock(host=srv, port=6697, ssl=True, proxies=proxies, timeout=self.timeout) - sock.connect() - sock.send('%s\n' % random.choice(['NICK', 'USER', 'JOIN', 'MODE', 'PART', 'INVITE', 'KNOCK', 'WHOIS', 'WHO', 'NOTICE', 'PRIVMSG', 'PING', 'QUIT'])) - return sock, proto, duration, torhost, srv + srv = random.choice(servers).strip() + try: + sock = rocksock.Rocksock(host=srv, port=6697, ssl=True, proxies=proxies, timeout=self.timeout) + sock.connect() + sock.send('%s\n' % random.choice(['NICK', 'USER', 'JOIN', 'MODE', 'PART', 'INVITE', 'KNOCK', 'WHOIS', 'WHO', 'NOTICE', 'PRIVMSG', 'PING', 'QUIT'])) + return sock, proto, duration, torhost, srv - except: sock.disconnect() + except: sock.disconnect() - return False, False, False, False, False + return False, False, False, False, False - def daemon(self, servers): - sqlite = mysqlite.mysqlite(self.database, str) - threadid = ''.join( [ random.choice(string.letters) for x in range(5) ] ) + def daemon(self, servers): + sqlite = mysqlite.mysqlite(self.database, str) + threadid = ''.join( [ random.choice(string.letters) for x in range(5) ] ) - q = 'SELECT proxy,failed,country,proto FROM proxylist WHERE failed