88 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
			
		
		
	
	
			88 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
| #!/usr/bin/env python3
 | |
| """
 | |
| 将本地 webshare 的 SOCKS5 代理通过 Tailscale 转发到甲骨文节点
 | |
| """
 | |
| 
 | |
| import subprocess
 | |
| import json
 | |
| import time
 | |
| import threading
 | |
| 
 | |
| # 配置
 | |
| ORACLE_TAILSCALE_IP = "100.x.x.x"  # 替换为你的甲骨文 Tailscale IP
 | |
| WEBSHARE_PROXIES_FILE = "webshare_proxies.txt"  # webshare 代理列表文件
 | |
| LOCAL_START_PORT = 20001  # 本地监听起始端口
 | |
| 
 | |
| def read_webshare_proxies():
 | |
|     """读取 webshare 代理列表"""
 | |
|     proxies = []
 | |
|     try:
 | |
|         with open(WEBSHARE_PROXIES_FILE, 'r') as f:
 | |
|             for line in f:
 | |
|                 line = line.strip()
 | |
|                 if line and ':' in line:
 | |
|                     # 格式: ip:port:username:password
 | |
|                     parts = line.split(':')
 | |
|                     if len(parts) >= 4:
 | |
|                         proxies.append({
 | |
|                             'host': parts[0],
 | |
|                             'port': parts[1], 
 | |
|                             'username': parts[2],
 | |
|                             'password': parts[3]
 | |
|                         })
 | |
|     except FileNotFoundError:
 | |
|         print(f"请创建 {WEBSHARE_PROXIES_FILE} 文件,每行一个代理: ip:port:username:password")
 | |
|         return []
 | |
|     
 | |
|     return proxies[:20]  # 只取前20个
 | |
| 
 | |
| def start_proxy_forward(local_port, oracle_port, webshare_proxy):
 | |
|     """启动单个代理转发"""
 | |
|     # 使用 gost 进行代理链转发
 | |
|     cmd = f"""gost -L socks5://:{local_port} -F socks5://{webshare_proxy['username']}:{webshare_proxy['password']}@{webshare_proxy['host']}:{webshare_proxy['port']}"""
 | |
|     
 | |
|     print(f"启动本地端口 {local_port} -> 甲骨文 {oracle_port} -> webshare {webshare_proxy['host']}:{webshare_proxy['port']}")
 | |
|     
 | |
|     try:
 | |
|         subprocess.run(cmd, shell=True)
 | |
|     except Exception as e:
 | |
|         print(f"代理转发失败 {local_port}: {e}")
 | |
| 
 | |
| def main():
 | |
|     # 读取 webshare 代理列表
 | |
|     webshare_proxies = read_webshare_proxies()
 | |
|     
 | |
|     if not webshare_proxies:
 | |
|         print("没有找到有效的 webshare 代理配置")
 | |
|         return
 | |
|     
 | |
|     print(f"找到 {len(webshare_proxies)} 个 webshare 代理")
 | |
|     
 | |
|     # 启动代理转发
 | |
|     threads = []
 | |
|     for i, proxy in enumerate(webshare_proxies):
 | |
|         local_port = LOCAL_START_PORT + i
 | |
|         oracle_port = 10001 + i
 | |
|         
 | |
|         thread = threading.Thread(
 | |
|             target=start_proxy_forward,
 | |
|             args=(local_port, oracle_port, proxy)
 | |
|         )
 | |
|         thread.daemon = True
 | |
|         thread.start()
 | |
|         threads.append(thread)
 | |
|         
 | |
|         time.sleep(0.1)  # 避免启动过快
 | |
|     
 | |
|     print(f"已启动 {len(threads)} 个代理转发")
 | |
|     print(f"本地 SOCKS5 代理端口: {LOCAL_START_PORT}-{LOCAL_START_PORT + len(webshare_proxies) - 1}")
 | |
|     
 | |
|     # 等待所有线程
 | |
|     try:
 | |
|         for thread in threads:
 | |
|             thread.join()
 | |
|     except KeyboardInterrupt:
 | |
|         print("\n正在停止代理转发...")
 | |
| 
 | |
| if __name__ == "__main__":
 | |
|     main() |