Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import threading
- import random
- import itertools
- from struct import pack
- import time
- import requests
- def get_my_ip():
- try:
- response = requests.get("http://icanhazip.com/")
- ip = response.text.strip()
- return ip
- except requests.RequestException:
- return None
- myip = get_my_ip()
- def is_socks5(ip, port):
- try:
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
- sock.settimeout(1)
- sock.connect((ip, port))
- sock.sendall(b"\x05\x01\x00")
- data = sock.recv(2)
- if len(data) < 2 or data[0] != 0x05 or data[1] != 0x00:
- return False
- return True
- except:
- return False
- def is_socks4(ip, port):
- try:
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
- sock.settimeout(1)
- sock.connect((ip, port))
- ipaddr = socket.inet_aton(ip)
- packet4 = b"\x04\x01" + pack(">H", port) + ipaddr + b"\x00"
- sock.sendall(packet4)
- data = sock.recv(8)
- if len(data) < 2 or data[0] != 0x00 or data[1] != 0x5A:
- return False
- return True
- except:
- return False
- def http_proxy(ip, port):
- global myip
- try:
- proxy = {"http": f"http://{ip}:{port}", "https": f"http://{ip}:{port}"}
- response = requests.get("http://icanhazip.com/", proxies=proxy, timeout=1)
- if response.status_code == 200 and (response.text.strip() == ip or response.text.strip() == myip):
- return True
- else:
- return False
- except requests.RequestException:
- return False
- def check_proxy(proxy_type, ip, port):
- if proxy_type == "socks5" and is_socks5(ip, port):
- return 5
- elif proxy_type == "socks4" and is_socks4(ip, port):
- return 4
- elif proxy_type == "http" and http_proxy(ip, port):
- return 1
- return 0
- def gen_ip():
- not_valid = [10, 127, 169, 172, 192]
- first = random.choice([i for i in range(1, 256) if i not in not_valid])
- ip = ".".join([str(first)] + [str(random.randint(1, 255)) for _ in range(3)])
- return ip
- def is_open(ip, port):
- try:
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
- sock.settimeout(0.5)
- result = sock.connect_ex((ip, port))
- return result == 0
- except:
- return False
- def scan_thread(file_handle):
- while True:
- try:
- ip = gen_ip()
- for port in [80, 1080, 8080, 3128]:
- if is_open(ip, port):
- proxy = f"{ip}:{port}"
- for proxy_type in ['socks5', 'socks4', 'http']:
- if check_proxy(proxy_type, ip, port):
- print(f"{proxy_type.upper()} {proxy}")
- file_handle.write(f"{proxy_type} {proxy}\n")
- file_handle.flush()
- break
- except Exception as e:
- print(str(e))
- pass
- def main():
- with open("proxies.txt", "a") as fh:
- threads = [threading.Thread(target=scan_thread, args=(fh,)) for _ in range(1024)]
- for thread in threads:
- thread.start()
- for thread in threads:
- thread.join()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement