Added Proxy functionality + proxy test function
This commit is contained in:
		
							parent
							
								
									efbae9689c
								
							
						
					
					
						commit
						035058b210
					
				
							
								
								
									
										26
									
								
								main.py
								
								
								
								
							
							
						
						
									
										26
									
								
								main.py
								
								
								
								
							|  | @ -5,9 +5,19 @@ import src.proxy as proxy | ||||||
| import os | import os | ||||||
| import glob | import glob | ||||||
| import json | import json | ||||||
|  | from dotenv import load_dotenv | ||||||
| from colorama import Style, Fore, init | from colorama import Style, Fore, init | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | def initialize(): | ||||||
|  | 
 | ||||||
|  |     # Init Environment | ||||||
|  |     load_dotenv() | ||||||
|  | 
 | ||||||
|  |     # Init Colorama | ||||||
|  |     init(autoreset=True) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| def readsites(p=None): | def readsites(p=None): | ||||||
| 
 | 
 | ||||||
|     dod = {} |     dod = {} | ||||||
|  | @ -28,14 +38,24 @@ def readsites(p=None): | ||||||
|     print(dod) |     print(dod) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | def proxytest(): | ||||||
|  |     one = proxy.Proxy | ||||||
|  |     one.name = "TEST PROXY" | ||||||
|  |     one.usr = os.getenv("PROXYUSR") | ||||||
|  |     one.pwd = os.getenv("PROXYPW") | ||||||
|  |     one.url = os.getenv("PROXYURL") | ||||||
|  |     one.port = os.getenv("PROXYPORT") | ||||||
|  | 
 | ||||||
|  |     proxy.test(one) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
| 
 | 
 | ||||||
|     num_monitors = 10 |     num_monitors = 10 | ||||||
| 
 | 
 | ||||||
|     # Initialize Colorama |     initialize() | ||||||
|     init(autoreset=True) |  | ||||||
| 
 |  | ||||||
|     readsites() |     readsites() | ||||||
|  |     proxytest() | ||||||
| 
 | 
 | ||||||
|     tools.clear() |     tools.clear() | ||||||
|     print(f"Creating {num_monitors} new Monitors...\n{tools.spacer}") |     print(f"Creating {num_monitors} new Monitors...\n{tools.spacer}") | ||||||
|  |  | ||||||
							
								
								
									
										32
									
								
								src/proxy.py
								
								
								
								
							
							
						
						
									
										32
									
								
								src/proxy.py
								
								
								
								
							|  | @ -1,9 +1,39 @@ | ||||||
|  | import requests | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def test(proxy): | ||||||
|  | 
 | ||||||
|  |     print(f'http://{proxy.usr}:{proxy.pwd}@{proxy.url}:{proxy.port}') | ||||||
|  | 
 | ||||||
|  |     try: | ||||||
|  |         r = requests.get( | ||||||
|  |             "http://example.com", | ||||||
|  |             proxies={ | ||||||
|  |                 'http': f'http://{proxy.usr}:{proxy.pwd}@{proxy.url}:{proxy.port}', | ||||||
|  |                 'https': f'http://{proxy.usr}:{proxy.pwd}@{proxy.url}:{proxy.port}' | ||||||
|  |             } | ||||||
|  |         ) | ||||||
|  | 
 | ||||||
|  |         if r.status_code == 200: | ||||||
|  |             proxy.isworking = True | ||||||
|  |         else: | ||||||
|  |             print(r.text) | ||||||
|  |             proxy.isworking = False | ||||||
|  | 
 | ||||||
|  |         print(f"{r.status_code} -> {proxy.isworking}") | ||||||
|  | 
 | ||||||
|  |     except Exception as e: | ||||||
|  |         print(f"Connection error! (Check proxy)\n\n{e}") | ||||||
|  |         proxy.isworking = False | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| class Proxy: | class Proxy: | ||||||
| 
 | 
 | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
| 
 | 
 | ||||||
|         self.name = None |         self.name = None | ||||||
|         self.url = None |         self.url = None | ||||||
|  |         self.port = None | ||||||
|         self.usr = None |         self.usr = None | ||||||
|         self.pwd = None |         self.pwd = None | ||||||
|         self.status = None |         self.isworking = None | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue