Advertisement
Sweetening

Proxy SockRaw Scan

Mar 6th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. import socket
  2. import threading
  3. import random
  4. import itertools
  5. from struct import pack
  6. import time
  7. import requests
  8.  
  9. def get_my_ip():
  10. try:
  11. response = requests.get("http://icanhazip.com/")
  12. ip = response.text.strip()
  13. return ip
  14. except requests.RequestException:
  15. return None
  16.  
  17. myip = get_my_ip()
  18.  
  19. def is_socks5(ip, port):
  20. try:
  21. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
  22. sock.settimeout(1)
  23. sock.connect((ip, port))
  24. sock.sendall(b"\x05\x01\x00")
  25. data = sock.recv(2)
  26. if len(data) < 2 or data[0] != 0x05 or data[1] != 0x00:
  27. return False
  28. return True
  29. except:
  30. return False
  31.  
  32. def is_socks4(ip, port):
  33. try:
  34. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
  35. sock.settimeout(1)
  36. sock.connect((ip, port))
  37. ipaddr = socket.inet_aton(ip)
  38. packet4 = b"\x04\x01" + pack(">H", port) + ipaddr + b"\x00"
  39. sock.sendall(packet4)
  40. data = sock.recv(8)
  41. if len(data) < 2 or data[0] != 0x00 or data[1] != 0x5A:
  42. return False
  43. return True
  44. except:
  45. return False
  46.  
  47. def http_proxy(ip, port):
  48. global myip
  49. try:
  50. proxy = {"http": f"http://{ip}:{port}", "https": f"http://{ip}:{port}"}
  51. response = requests.get("http://icanhazip.com/", proxies=proxy, timeout=1)
  52. if response.status_code == 200 and (response.text.strip() == ip or response.text.strip() == myip):
  53. return True
  54. else:
  55. return False
  56. except requests.RequestException:
  57. return False
  58.  
  59. def check_proxy(proxy_type, ip, port):
  60. if proxy_type == "socks5" and is_socks5(ip, port):
  61. return 5
  62. elif proxy_type == "socks4" and is_socks4(ip, port):
  63. return 4
  64. elif proxy_type == "http" and http_proxy(ip, port):
  65. return 1
  66. return 0
  67.  
  68. def gen_ip():
  69. not_valid = [10, 127, 169, 172, 192]
  70. first = random.choice([i for i in range(1, 256) if i not in not_valid])
  71. ip = ".".join([str(first)] + [str(random.randint(1, 255)) for _ in range(3)])
  72. return ip
  73.  
  74. def is_open(ip, port):
  75. try:
  76. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
  77. sock.settimeout(0.5)
  78. result = sock.connect_ex((ip, port))
  79. return result == 0
  80. except:
  81. return False
  82.  
  83. def scan_thread(file_handle):
  84. while True:
  85. try:
  86. ip = gen_ip()
  87. for port in [80, 1080, 8080, 3128]:
  88. if is_open(ip, port):
  89. proxy = f"{ip}:{port}"
  90. for proxy_type in ['socks5', 'socks4', 'http']:
  91. if check_proxy(proxy_type, ip, port):
  92. print(f"{proxy_type.upper()} {proxy}")
  93. file_handle.write(f"{proxy_type} {proxy}\n")
  94. file_handle.flush()
  95. break
  96. except Exception as e:
  97. print(str(e))
  98. pass
  99.  
  100. def main():
  101. with open("proxies.txt", "a") as fh:
  102. threads = [threading.Thread(target=scan_thread, args=(fh,)) for _ in range(1024)]
  103. for thread in threads:
  104. thread.start()
  105. for thread in threads:
  106. thread.join()
  107.  
  108. if __name__ == "__main__":
  109. main()
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement