├── README.md ├── proxy_tester_menu.py └── socker.py /README.md: -------------------------------------------------------------------------------- 1 | # SOCKER 2 | 3 | Checks for valid SOCKS4 & SOCKS5 proxies. 4 | This code is Python3 port of [SOCKS-Proxy-Checker](https://github.com/BeastsMC/SOCKS-Proxy-Checker/) which was written in Python2 5 | This code runs on python3. 6 | 7 | ## HOW To RUN 8 | 9 | For Help Type 10 | 11 | ```python3 socker.py -h``` 12 | 13 | Command Line Usage: 14 | 15 | ```python3 socker.py -i -o -th -t ``` 16 | 17 | You can use the auto mode for fetching proxies from default APIs. 18 | 19 | ```python3 socker.py -auto -o -th -t ``` 20 | 21 | You can use the URL mode to add new urls to fetch proxies. 22 | 23 | ```python3 socker.py -u proxlylist1.site -u proxlylist2.site -o -th -t ``` 24 | 25 | All the parameters are optional. 26 | File, Auto, URL modes can be used simulaenously to gather more proxies. 27 | The default thread count is 30 and timeout is 5 seconds. 28 | 29 | ### SOME TERMS 30 | 31 | Proxy list - An absolute path to the file containing a list of proxies in the of IP:Port 32 | 33 | Output file - An absolute path to the file that the live SOCKS4/5 proxies will be written to. 34 | 35 | Threads - The number of threads that will be used to check proxies. More threads = quicker 36 | scanning. If the thread count is too high, your internet connection may be interrupted and 37 | false timeouts/connection refused errors will be printed. 38 | 39 | Timeout - The amount of time to give a potential proxy to repond before giving up and trying 40 | the next. 41 | 42 | This script attempts to verify if a given IP:Port listing is a SOCKS4/5 proxy by completeing a 43 | SOCKS4/5 handshake with it. In order to maintain the highest level of compatibility I could, I 44 | did not use third party libraries and stuck with the default Python libraries. 45 | 46 | ## SOCKSLIST 47 | 48 | You can Also Use My PROXY List to get New SOCKS Proxy. It Gets Updated Every 24 hours. 49 | 50 | PROXY-List Link : [https://github.com/TheSpeedX/PROXY-List](https://github.com/TheSpeedX/PROXY-List) 51 | 52 | ## Test http & https proxy using proxy_tester_menu.py 53 | 54 | To use this script, follow these steps: 55 | 56 | 1. Ensure you have the `requests` library installed. You can install it using `pip install requests` if needed. 57 | 2. Create two files named `http.txt` and `https.txt` in the same directory as the script. Each file should contain a list of IP addresses to test, with one IP per line. 58 | 3. Run the script using the command: `python proxy_tester_menu.py`. 59 | 4. The menu will be displayed, prompting you to select a file to test. Enter your choice by typing `1` or `2`. 60 | 5. If the chosen file is not found or empty, an error message will be displayed. Make sure the file contains valid IP addresses. 61 | 6. The script will start testing the IP addresses using the selected file. An animation will be displayed to indicate the progress of testing. 62 | 7. Once the testing is completed, the results will be saved in a file named `results.txt` in the same directory. 63 | 8. The message "Testing complete. Results are saved to results.txt" will be displayed. 64 | Make sure to have the required `http.txt` and `https.txt` files in the same directory as the script and ensure they contain valid IP addresses. 65 | 66 | Sample domains you can set: 67 | 68 | ``` 69 | www.google.com 70 | www.example.com 71 | www.yahoo.com 72 | www.microsoft.com 73 | www.facebook.com 74 | www.instagram.com 75 | www.twitter.com 76 | www.amazon.com 77 | www.netflix.com 78 | www.reddit.com 79 | www.wikipedia.org 80 | www.apple.com 81 | www.linkedin.com 82 | www.github.com 83 | www.stackoverflow.com 84 | www.spotify.com 85 | www.dropbox.com 86 | www.pinterest.com 87 | www.tumblr.com 88 | www.airbnb.com 89 | ``` 90 | 91 | ## CONTACT 92 | 93 | For Any Queries: 94 | Ping Me : [Telegram](http://t.me/the_space_bar) 95 | -------------------------------------------------------------------------------- /proxy_tester_menu.py: -------------------------------------------------------------------------------- 1 | import contextlib 2 | import time 3 | import requests 4 | import os 5 | 6 | DEFAULT_DOMAIN = "www.google.com" 7 | 8 | 9 | def test_proxy(ip, domain=DEFAULT_DOMAIN): 10 | proxies = { 11 | "http": f"http://{ip}", 12 | "https": f"http://{ip}", 13 | } 14 | with contextlib.suppress(requests.RequestException): 15 | response = requests.get(f"http://{domain}", proxies=proxies, timeout=5) 16 | if response.status_code >= 200 and response.status_code < 300: 17 | return True 18 | return False 19 | 20 | 21 | def test_ip_addresses(ip_file, output_file, domain=DEFAULT_DOMAIN): 22 | with open(ip_file, "r") as file: 23 | ip_addresses = file.read().splitlines() 24 | 25 | results = [] 26 | 27 | for i, ip in enumerate(ip_addresses, start=1): 28 | is_working = test_proxy(ip, domain=domain) 29 | status = "Active" if is_working else "Inactive" 30 | results.append((ip, status)) 31 | 32 | progress = i / len(ip_addresses) * 100 33 | print( 34 | f'\rTesting - Progress: {progress:.1f}% | {"." * (i % 4)} ', 35 | end="", 36 | flush=True, 37 | ) 38 | time.sleep(0.1) # Add a slight delay to simulate animation 39 | 40 | with open(output_file, "w") as file: 41 | for ip, status in results: 42 | file.write(f"{ip}\t{status}\n") 43 | 44 | print("\rTesting complete. ") 45 | 46 | 47 | def display_menu(): 48 | print("Select a file to test:") 49 | print("1. http.txt") 50 | print("2. https.txt") 51 | 52 | 53 | def get_user_choice(): 54 | while True: 55 | choice = input("Enter your choice (1 or 2): ") 56 | if choice in ["1", "2"]: 57 | return choice 58 | print("Invalid choice. Please try again.") 59 | 60 | 61 | def get_input_filename(choice): 62 | if choice == "1": 63 | return "http.txt" 64 | elif choice == "2": 65 | return "https.txt" 66 | 67 | 68 | def check_input_files(): 69 | http_file = "http.txt" 70 | https_file = "https.txt" 71 | if not os.path.exists(http_file) or not os.path.isfile(http_file): 72 | print(f"Error: '{http_file}' file is missing or not found.") 73 | return False 74 | if not os.path.exists(https_file) or not os.path.isfile(https_file): 75 | print(f"Error: '{https_file}' file is missing or not found.") 76 | return False 77 | return True 78 | 79 | 80 | def get_domain_choice(): 81 | domain_choice = input( 82 | "Enter the domain on which you want to test the proxies (default: www.google.com): " 83 | ) 84 | return domain_choice.strip() or DEFAULT_DOMAIN 85 | 86 | 87 | def main(): 88 | if not check_input_files(): 89 | return 90 | 91 | display_menu() 92 | choice = get_user_choice() 93 | input_file = get_input_filename(choice) 94 | output_file = "results.txt" 95 | 96 | print("Testing in progress...") 97 | time.sleep(1) # Simulate a delay before starting the testing 98 | 99 | domain = get_domain_choice() 100 | print(f"Using domain: {domain}") 101 | 102 | test_ip_addresses(input_file, output_file, domain=domain) 103 | 104 | print("Testing complete. Results saved to", output_file) 105 | 106 | 107 | if __name__ == "__main__": 108 | main() 109 | -------------------------------------------------------------------------------- /socker.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | import socket 5 | import threading 6 | import time 7 | import sys 8 | 9 | # from random import * 10 | import struct 11 | import argparse 12 | import re 13 | from urllib.request import Request, urlopen # Python 3 14 | import queue as Queue 15 | 16 | 17 | __author__ = "TheSpeedX" 18 | __version__ = "2.0" 19 | 20 | banner = """ 21 | ███████╗ ██████╗ ██████╗██╗ ██╗███████╗██████╗ 22 | ██╔════╝██╔═══██╗██╔════╝██║ ██╔╝██╔════╝██╔══██╗ 23 | ███████╗██║ ██║██║ █████╔╝ █████╗ ██████╔╝ 24 | ╚════██║██║ ██║██║ ██╔═██╗ ██╔══╝ ██╔══██╗ 25 | ███████║╚██████╔╝╚██████╗██║ ██╗███████╗██║ ██║ 26 | ╚══════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ 27 | Check Valid Working SOCKS Proxy 28 | """ 29 | socksProxies = Queue.Queue() 30 | checkQueue = Queue.Queue() 31 | 32 | 33 | class ThreadChecker(threading.Thread): 34 | def __init__(self, queue, timeout): 35 | self.timeout = timeout 36 | self.q = queue 37 | threading.Thread.__init__(self) 38 | 39 | def isSocks4(self, host, port, soc): 40 | 41 | ipaddr = socket.inet_aton(host) 42 | port_pack = struct.pack(">H", port) 43 | packet4 = b"\x04\x01" + port_pack + ipaddr + b"\x00" 44 | soc.sendall(packet4) 45 | data = soc.recv(8) 46 | if len(data) < 2: 47 | # Null response 48 | return False 49 | if data[0] != int("0x00", 16): 50 | # Bad data 51 | return False 52 | if data[1] != int("0x5A", 16): 53 | # Server returned an error 54 | return False 55 | return True 56 | 57 | def isSocks5(self, host, port, soc): 58 | soc.sendall(b"\x05\x01\x00") 59 | data = soc.recv(2) 60 | if len(data) < 2: 61 | # Null response 62 | return False 63 | if data[0] != int("0x05", 16): 64 | # Not socks5 65 | return False 66 | if data[1] != int("0x00", 16): 67 | # Requires authentication 68 | return False 69 | return True 70 | 71 | def getSocksVersion(self, proxy): 72 | host, port = proxy.split(":") 73 | try: 74 | port = int(port) 75 | if port < 0 or port > 65536: 76 | print(f"Invalid: {proxy}") 77 | return 0 78 | except Exception: 79 | print(f"Invalid: {proxy}") 80 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 81 | s.settimeout(self.timeout) 82 | try: 83 | s.connect((host, port)) 84 | if self.isSocks4(host, port, s): 85 | s.close() 86 | return 4 87 | elif self.isSocks5(host, port, s): 88 | s.close() 89 | return 5 90 | else: 91 | print(f"Not a SOCKS: {proxy}") 92 | s.close() 93 | return 0 94 | except socket.timeout: 95 | print(f"Timeout: {proxy}") 96 | s.close() 97 | return 0 98 | except socket.error: 99 | print(f"Connection refused: {proxy}") 100 | s.close() 101 | return 0 102 | 103 | def run(self): 104 | while True: 105 | proxy = self.q.get() 106 | version = self.getSocksVersion(proxy) 107 | if version in [5, 4]: 108 | print(f"Working: {proxy}") 109 | socksProxies.put(proxy) 110 | self.q.task_done() 111 | 112 | 113 | class ThreadWriter(threading.Thread): 114 | def __init__(self, queue, outputPath): 115 | self.q = queue 116 | self.outputPath = outputPath 117 | threading.Thread.__init__(self) 118 | 119 | def run(self): 120 | while True: 121 | toWrite = self.q.qsize() 122 | with open(self.outputPath, "a+") as outputFile: 123 | for _ in range(toWrite): 124 | proxy = self.q.get() 125 | outputFile.write(proxy + "\n") 126 | self.q.task_done() 127 | time.sleep(10) 128 | 129 | 130 | def info(): 131 | print(banner) 132 | print(f"Author: {__author__} \t\t Version: {__version__}") 133 | 134 | 135 | def Exit(): 136 | print(banner) 137 | print("\tThanks For using socker !!!") 138 | sys.exit() 139 | 140 | 141 | def get_timestamp(): 142 | return time.strftime("%Y%m%d_%H%M%S") 143 | 144 | 145 | def get_proxies(sources, is_url=False): 146 | pattern = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{2,5}" 147 | data = "" 148 | for source in sources: 149 | try: 150 | if is_url: 151 | req = Request( 152 | source, 153 | headers={ 154 | "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36" 155 | }, 156 | ) 157 | response = urlopen(req) 158 | data += response.read().decode("utf-8") + "\n" 159 | else: 160 | with open(source) as file: 161 | data += file.read() + "\n" 162 | print(f"Processed: {source}") 163 | except Exception: 164 | print(f"Skipping, Error Occured: {source}") 165 | return re.findall(pattern, data) 166 | 167 | 168 | def start_socker(proxies, outputPath, threads, timeout): 169 | print(f"Loaded {len(proxies)} proxies !!!") 170 | for proxy in proxies: 171 | checkQueue.put(proxy) 172 | for _ in range(threads): 173 | thread = ThreadChecker(checkQueue, timeout) 174 | thread.setDaemon(True) 175 | thread.start() 176 | time.sleep(0.25) 177 | wT = ThreadWriter(socksProxies, outputPath) 178 | wT.setDaemon(True) 179 | wT.start() 180 | checkQueue.join() 181 | socksProxies.join() 182 | Exit() 183 | 184 | 185 | description = """socker - Check For Valid SOCKS Proxy 186 | 187 | socker can utilize multiple sources like file, inbuilt apis, custom urls. 188 | File Mode: 189 | python3 socker.py -i proxys_to_be_checked.txt 190 | URL Mode: 191 | python3 socker.py -u proxlylist1.site -u proxlylist2.site 192 | Auto Mode: 193 | python3 socker.py -auto 194 | 195 | These modes can also be used simultaneously to gather more proxies. 196 | python3 socker.py -i proxys_to_be_checked.txt -auto 197 | 198 | socker is not intented for malicious uses. 199 | """ 200 | 201 | parser = argparse.ArgumentParser( 202 | description=description, 203 | epilog="Coded by SpeedX !!!", 204 | formatter_class=argparse.RawTextHelpFormatter, 205 | ) 206 | parser.add_argument( 207 | "-o", 208 | "--output", 209 | default=f"live_proxies_{get_timestamp()}.txt", 210 | help="Write Proxies to this file", 211 | ) 212 | parser.add_argument( 213 | "-th", "--thread", type=int, default=30, help="Number of concurrent threads to run" 214 | ) 215 | parser.add_argument( 216 | "-t", 217 | "--timeout", 218 | type=float, 219 | default=5.0, 220 | help="Maximum time to wait for response(seconds)", 221 | ) 222 | parser.add_argument( 223 | "-i", "--input", action="append", help="Input File containing proxy" 224 | ) 225 | parser.add_argument( 226 | "-auto", "--auto", action="store_true", help="Fetches proxy from Proxyscrape" 227 | ) 228 | parser.add_argument("-u", "--url", action="append", help="Fetch proxy from custom URL") 229 | parser.add_argument( 230 | "-v", "--version", action="store_true", help="show current TBomb version" 231 | ) 232 | 233 | if __name__ == "__main__": 234 | args = parser.parse_args() 235 | info() 236 | if args.version: 237 | print("Author: ", __author__) 238 | print("Version: ", __version__) 239 | else: 240 | proxies = [] 241 | proxy_api = [ 242 | "https://raw.githubusercontent.com/TheSpeedX/SOCKS-List/master/socks4.txt", 243 | "https://raw.githubusercontent.com/TheSpeedX/SOCKS-List/master/socks5.txt", 244 | ] 245 | if args.input: 246 | proxies.extend(get_proxies(args.input)) 247 | if args.auto: 248 | proxies.extend(get_proxies(proxy_api, is_url=True)) 249 | if args.url: 250 | proxies.extend(get_proxies(args.url, is_url=True)) 251 | if proxies: 252 | start_socker(proxies, args.output, args.thread, args.timeout) 253 | else: 254 | print("No proxies found !!!") 255 | Exit() 256 | --------------------------------------------------------------------------------