You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.4KB

  1. #!/usr/bin/python3
  2. import sys
  3. import time
  4. import requests
  5. import socket
  6. from argparse import ArgumentParser
  7. proxy_list = dict()
  8. throttle=0.5
  9. def main():
  10. args = getargs()
  11. last_i = 0
  12. i=1
  13. types=list()
  14. if not args.socks5 and not args.socks4 and not args.http:
  15. print("[!] Error! Please select at least one protocol...")
  16. return
  17. if args.socks5:
  18. types.append("socks5")
  19. if args.socks4:
  20. types.append("socks4")
  21. if args.http:
  22. types.append("http")
  23. while True:
  24. if i > args.count:
  25. break
  26. if i > last_i:
  27. print(f"[*] Getting proxy num {i}...")
  28. last_i = i
  29. time.sleep(throttle)
  30. r = requests.get("https://gimmeproxy.com/api/getProxy")
  31. ret = r.json()
  32. print(ret)
  33. if 'protocol' in ret:
  34. if (ret['protocol'] in types):
  35. try:
  36. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  37. s.settimeout(5)
  38. s.connect((ret['ip'], int(ret['port'])))
  39. s.close()
  40. except:
  41. print("[x] Proxy not responding...")
  42. continue
  43. if not ret['protocol'] in proxy_list:
  44. proxy_list[ret['protocol']] = list()
  45. proxy_list[ret['protocol']].append( (ret['ip'], ret['port'], ret['country']) )
  46. i+=1
  47. for proto in proxy_list:
  48. print(f"-- {proto} --")
  49. for proxy in proxy_list[proto]:
  50. print(f"{proto} {proxy[0]} {proxy[1]} # {proxy[2]}")
  51. print("")
  52. if args.output:
  53. with open(args.output, "w") as f:
  54. for proto in proxy_list:
  55. f.write(f"# {proto}\n")
  56. for proxy in proxy_list[proto]:
  57. f.write(f"{proto} {proxy[0]} {proxy[1]} # {proxy[2]}\n")
  58. def getargs():
  59. p = ArgumentParser()
  60. p.add_argument("-c", "--count", help="How many proxies to fetch", default=10, type=int)
  61. p.add_argument("-s5", "--socks5", help="Getting socks5 proxies", action="store_true", default=False)
  62. p.add_argument("-s4", "--socks4", help="Getting socks4 proxies", action="store_true", default=False)
  63. p.add_argument("-ht", "--http", help="Getting http proxies", action="store_true", default=False)
  64. p.add_argument("-o", "--output", help="Output to file")
  65. return p.parse_args()
  66. if __name__=='__main__':
  67. main()