Advertisement
XenoTheStrange

Check socks4 and socks5 proxies [Python, Curl]

Aug 29th, 2022 (edited)
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. """This checks socks4 and socks5 and socks4 proxies using curl.
  4. It is necessary to make a proxies.txt file and put the urls in this form:
  5. sockstype://ip:port ex socks5://127.0.0.1:9050"""
  6.  
  7. import subprocess as sub
  8. import time
  9.  
  10. timeout = "5"
  11. debug = False
  12.  
  13. check_hosts = [
  14.     "ifconfig.me",
  15.     "api.ipify.org",
  16.     "bot.whatismyipaddress.com",
  17.     "ipinfo.io/ip",
  18.     "ipecho.net/plain"
  19.     ]
  20. def log_good(string):
  21.     with open("good_proxies.txt","a") as good_proxies:
  22.         good_proxies.write(string)
  23.         good_proxies.close()
  24.  
  25. proxies = open("proxies.txt", "r").read().split("\n")
  26. total = len(proxies)
  27.  
  28. for i, ip in enumerate(proxies):
  29.     if not i=="":
  30.         try:
  31.             print(f"{i}/{total} Checking {ip}")
  32.             sockstype, ip = ip.split("://")
  33.             t1 = time.time()
  34.             result = sub.check_output(["curl","-s","--connect-timeout",timeout,f"--{sockstype}",ip,check_hosts[0]])
  35.             if debug == True:print(f"curl -s --connect-timeout {timeout} --{sockstype} {ip} {check_hosts[0]}")
  36.             t2 = time.time()
  37.             total_time = t2 - t1
  38.             print(f"{ip} responded in {t2 - t1} seconds")
  39.             log_good(f"{sockstype}://{ip} {round(total_time,1)}\n")
  40.         except Exception as e:
  41.             if debug == True:
  42.                 print(f"curl -s --connect-timeout {timeout} --{sockstype} {ip} {check_hosts[0]}")
  43.                 print(e)
  44.                 print("\n")
  45.             pass
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement