Mr-Risov/Telegram_reporting_system
0
1import os2try:3 import requests4 from time import sleep5 from configparser import ConfigParser6 from os import system, name7 from threading import Thread, active_count8 from re import search, compile9except:10 os.system('pip install requests')11 os.system('pip install configparser')12THREADS = 50013PROXIES_TYPES = ('http', 'socks4', 'socks5')14USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36'15REGEX = compile(r"(?:^|\D)?(("+ r"(?:[1-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])"16 + r"\." + r"(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])"17 + r"\." + r"(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])"18 + r"\." + r"(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])"19 + r"):" + (r"(?:\d|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}"20 + r"|65[0-4]\d{2}|655[0-2]\d|6553[0-5])")21 + r")(?:\D|$)")22 23errors = open('errors.txt', 'a+')24cfg = ConfigParser(interpolation=None)25cfg.read("config.ini", encoding="utf-8")26 27http, socks4, socks5 = '', '', ''28try: http, socks4, socks5 = cfg["HTTP"], cfg["SOCKS4"], cfg["SOCKS5"]29except KeyError: print(' [ OUTPUT ] Error | config.ini not found!');sleep(3);exit()30 31http_proxies, socks4_proxies, socks5_proxies = [], [], []32time_out = 1533 34def save_proxies(proxies, proxy_type):35 with open(f"{proxy_type}_proxies.txt", 'w') as file:36 for proxy in proxies:37 file.write(proxy + '\n')38 39def scrap(sources, _proxy_type):40 proxies = []41 for source in sources:42 if source:43 try:44 response = requests.get(source, timeout=time_out)45 if tuple(REGEX.finditer(response.text)):46 for proxy in tuple(REGEX.finditer(response.text)):47 proxies.append(proxy.group(1))48 except Exception as e:49 errors.write(f'{e}\n')50 51 if _proxy_type == 'http':52 save_proxies(proxies, 'http')53 elif _proxy_type == 'socks4':54 save_proxies(proxies, 'socks4')55 elif _proxy_type == 'socks5':56 save_proxies(proxies, 'socks5')57 58def start_scrap():59 threads = []60 for i in (http_proxies, socks4_proxies, socks5_proxies): i.clear()61 for i in ((http.get("Sources").splitlines(), 'http'), (socks4.get("Sources").splitlines(), 'socks4'), (socks5.get("Sources").splitlines(), 'socks5')):62 thread = Thread(target=scrap, args=(i[0], i[1]))63 threads.append(thread)64 thread.start()65 for t in threads: t.join()66 67def start_view():68 c, threads = 0, []69 start_scrap()70 71 72Thread(target=start_view).start()