From 11c5bd67b328a5ac40da2ea3046dcac3ba6f252b Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 3 Jul 2021 17:16:52 +0200 Subject: [PATCH] add http check --- proxywatchd.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/proxywatchd.py b/proxywatchd.py index 82831be..e80165e 100644 --- a/proxywatchd.py +++ b/proxywatchd.py @@ -58,11 +58,17 @@ class WorkerJob(): self.country = country self.isoldies = oldies - def connect_socket(self): - srvname = random.choice(config.servers).strip() + def connect_socket(self, checktype): + if checktype == 'irc': + srvname = random.choice(config.servers).strip() + use_ssl = random.choice([0,1]) if config.watchd.use_ssl == 2 else config.watchd.use_ssl + server_port = 6697 if use_ssl else 6667 + elif checktype == 'http': + srvname = random.choice( ['www.facebook.com', 'www.reddit.com', 'www.twitter.com'] ) + use_ssl = random.choice([0,1]) if config.watchd.use_ssl == 2 else config.watchd.use_ssl + server_port = 443 if use_ssl else 80 + protos = ['http', 'socks5', 'socks4'] if self.proto is None else [self.proto] - use_ssl = random.choice([0,1]) if config.watchd.use_ssl == 2 else config.watchd.use_ssl - server_port = 6697 if use_ssl else 6667 fail_inc = 1 @@ -77,7 +83,6 @@ class WorkerJob(): if not srv: continue duration = time.time() - #rocksock.RocksockProxyFromURL('socks4://%s' % torhost), proxies = [ rocksock.RocksockProxyFromURL('socks5://%s' % torhost), rocksock.RocksockProxyFromURL('%s://%s' % (proto, self.proxy)), @@ -86,7 +91,10 @@ class WorkerJob(): try: sock = rocksock.Rocksock(host=srv, port=server_port, ssl=use_ssl, proxies=proxies, timeout=config.watchd.timeout) sock.connect() - sock.send('NICK\n') + if checktype == 'irc': + sock.send('NICK\n') + elif checktype == 'http': + sock.send('HEAD / HTTP/1.0\r\nHost: %s\r\n\r\n' % srvname) return sock, proto, duration, torhost, srvname, 0 except rocksock.RocksockException as e: if config.watchd.debug: @@ -123,17 +131,19 @@ class WorkerJob(): def run(self): self.checktime = int(time.time()) + checktype = config.watchd.checktype - sock, proto, duration, tor, srv, failinc = self.connect_socket() + sock, proto, duration, tor, srv, failinc = self.connect_socket(checktype) if not sock: self.failcount += failinc return try: - recv = sock.recv(6) - #recv = sock.recvline() + recv = sock.recv(-1) + #print(recv) + regex = '^(:|NOTICE|ERROR)' if checktype == 'irc' else '(X-FB-Debug|x-clacks-overhead|x-connection-hash):' # good data - if re.match('^(:|NOTICE|ERROR)', recv, re.IGNORECASE): + if (checktype == 'irc' and re.match(regex, recv, re.IGNORECASE)) or (checktype == 'http' and re.finditer(regex, recv, re.MULTILINE)): duration = (time.time() - duration) if geolite and not self.country or self.country == 'unknown' or self.country == 'N/A':