|
| 1 | +#!/usr/bin/python3 |
| 2 | + |
| 3 | +''' |
| 4 | + PROX - utility for checking proxy in terminal under the GNU GPL V3.0 Licensy |
| 5 | + AUTHORS: Hasanov Abdurahmon & Ilyosiddin Kalandar, MySql Part Created By Pasan Laksitha |
| 6 | + Version: 0.3 with MySql You can check Main Edition from GitHub:-pythonism |
| 7 | +''' |
| 8 | + |
| 9 | +from sys import argv |
| 10 | +import urllib3 |
| 11 | +from os import system as terminal |
| 12 | +import requests |
| 13 | +from colorama import Fore,Style |
| 14 | +import MySQLdb |
| 15 | + |
| 16 | +URL = "http://google.com" |
| 17 | +CMD_CLEAR_TERM = "clear" |
| 18 | +TIMEOUT = (3.05,27) |
| 19 | +db_commits = 0 |
| 20 | + |
| 21 | +mydb = MySQLdb.connect(host='localhost', |
| 22 | + user='', |
| 23 | + passwd='', |
| 24 | + db='proxy') |
| 25 | +cursor = mydb.cursor() |
| 26 | + |
| 27 | +def check_proxy(proxy): |
| 28 | + ''' |
| 29 | + Function for check proxy return ERROR |
| 30 | + if proxy is Bad else |
| 31 | + Function return None |
| 32 | + ''' |
| 33 | + try: |
| 34 | + session = requests.Session() |
| 35 | + session.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36' |
| 36 | + session.max_redirects = 300 |
| 37 | + proxy = proxy.split('\n',1)[0] |
| 38 | + print(Fore.LIGHTYELLOW_EX + 'Checking ' + proxy) |
| 39 | + session.get(URL, proxies={'http':'http://' + proxy}, timeout=TIMEOUT,allow_redirects=True) |
| 40 | + except requests.exceptions.ConnectionError as e: |
| 41 | + print(Fore.LIGHTRED_EX + 'Error!') |
| 42 | + return e |
| 43 | + except requests.exceptions.ConnectTimeout as e: |
| 44 | + print(Fore.LIGHTRED_EX + 'Error,Timeout!') |
| 45 | + return e |
| 46 | + except requests.exceptions.HTTPError as e: |
| 47 | + print(Fore.LIGHTRED_EX + 'HTTP ERROR!') |
| 48 | + return e |
| 49 | + except requests.exceptions.Timeout as e: |
| 50 | + print(Fore.LIGHTRED_EX + 'Error! Connection Timeout!') |
| 51 | + return e |
| 52 | + except urllib3.exceptions.ProxySchemeUnknown as e: |
| 53 | + print(Fore.LIGHTRED_EX + 'ERROR unkown Proxy Scheme!') |
| 54 | + return e |
| 55 | + except requests.exceptions.TooManyRedirects as e: |
| 56 | + print(Fore.LIGHTRED_EX + 'ERROR! Too many redirects!') |
| 57 | + return e |
| 58 | +def print_help(): |
| 59 | + terminal(CMD_CLEAR_TERM) |
| 60 | + print(Fore.LIGHTGREEN_EX + 'PROX v0.2 - Utility for checking proxy in terminal') |
| 61 | + print(Fore.LIGHTGREEN_EX + 'Authors: Hasanov Abdurahmon & Ilyosiddin Kalandar, MySql Part Created By Pasan Laksitha') |
| 62 | + print(Fore.LIGHTCYAN_EX) |
| 63 | + print('Usage -> prox -f <filename> - Check file with proxies') |
| 64 | + print('prox -p <proxy> - check only one proxy') |
| 65 | + print('prox --help - show this menu') |
| 66 | + |
| 67 | +if len(argv) > 1: |
| 68 | + commands = ['--help','-h','-f','-p','/?','--file','-file','--proxy','-proxy'] |
| 69 | + if argv[1] in commands: |
| 70 | + if argv[1] in ('--help','-help','/?','--?'): |
| 71 | + print_help() |
| 72 | + elif argv[1] in ('-f','--file','-file'): |
| 73 | + try: |
| 74 | + file = open(argv[2]) |
| 75 | + proxies = list(file) |
| 76 | + goods = 0 |
| 77 | + terminal(CMD_CLEAR_TERM) |
| 78 | + print(Fore.LIGHTCYAN_EX + '===========================================') |
| 79 | + for proxy in proxies: |
| 80 | + try: |
| 81 | + if check_proxy(proxy): |
| 82 | + print(Fore.LIGHTRED_EX + 'Bad proxy ' + proxy) |
| 83 | + else: |
| 84 | + print(Fore.LIGHTGREEN_EX + 'Good proxy ' + proxy) |
| 85 | + file_with_goods = open('good.txt','a') |
| 86 | + file_with_goods.write(proxy) |
| 87 | + goods += 1 |
| 88 | + try: |
| 89 | + cursor.execute(f"INSERT INTO proxy (proxy) VALUES ('{proxy}');") |
| 90 | + mydb.commit() |
| 91 | + print("DB Commited") |
| 92 | + db_commits += 1 |
| 93 | + except: |
| 94 | + print("DB NOT Commited") |
| 95 | + |
| 96 | + print(Fore.LIGHTCYAN_EX + '=================================================') |
| 97 | + except KeyboardInterrupt: |
| 98 | + print(Fore.LIGHTGREEN_EX + '\nExit.') |
| 99 | + exit() |
| 100 | + print(Fore.LIGHTGREEN_EX + 'Total ' + str(goods) + ' good proxies found') |
| 101 | + print(Fore.LIGHTRED_EX + 'And ' + str(len(proxies) - goods) + ' is bad') |
| 102 | + print(Fore.LIGHTYELLOW_EX + 'Have nice day! :)') |
| 103 | + print() |
| 104 | + except FileNotFoundError: |
| 105 | + print(Fore.LIGHTRED_EX + 'Error!\nFile Not found!') |
| 106 | + except IndexError: |
| 107 | + print(Fore.LIGHTRED_EX + 'Error!\nMissing filename!') |
| 108 | + elif argv[1] in ('-p','--proxy','-proxy'): |
| 109 | + try: |
| 110 | + argv[2] = argv[2].split(' ')[0] |
| 111 | + if check_proxy(argv[2]): |
| 112 | + print(Fore.LIGHTRED_EX + 'BAD PROXY ' + argv[2]) |
| 113 | + else: |
| 114 | + print(Fore.LIGHTGREEN_EX + 'GOOD PROXY ' + argv[2]) |
| 115 | + try: |
| 116 | + cursor.execute(f"INSERT INTO proxy (proxy) VALUES ('{proxy}');") |
| 117 | + mydb.commit() |
| 118 | + print("DB Commited") |
| 119 | + db_commits += 1 |
| 120 | + except: |
| 121 | + print("DB NOT Commited") |
| 122 | + except IndexError: |
| 123 | + print(Fore.LIGHTRED_EX + 'Error! Missing proxy!') |
| 124 | + else: |
| 125 | + print(Fore.LIGHTRED_EX + 'Unknown option \"' + argv[1] + '\"') |
| 126 | +else: |
| 127 | + print_help() |
0 commit comments