我正在尝试运行具有 3 个线程的 python 脚本,其中一个是使用线程模块使用 pyngrok 将即将到来的连接端口转发到 localhost,但问题是每当 ngrok 服务器启动时,它都会挂起所有其他线程......
def CreateTunnel(self):
try:
ngrok.set_auth_token(self.AuthToken)
print(f"{Fore.GREEN}[+] Opening TCP tunnel {Style.RESET_ALL}")
tunnel = ngrok.connect(addr=self.port, proto="tcp")
print(f"{Fore.GREEN}[+] Public URL:{Style.RESET_ALL} {Fore.CYAN}{ngrok.get_tunnels()[0]}{Style.RESET_ALL}")
ngrok_proc = ngrok.get_ngrok_process()
self.pub_url = tunnel.public_url.split("tcp://")[1]
self.ngrokPort = tunnel.public_url.split("tcp://")[1].split(":")[1]
ngrok_proc.proc.wait() # Hangs the process and other threads stops execution
如何同步运行 3 个线程?或者我如何在不需要使用 proc.wait() 的情况下设置 ngrok 服务器?
这是线程的调用方式:
def Threads(self):
# Adding them to a list
if self.ngrok:
self.jobs.append(th(target=self.CreateTunnel()))
self.jobs.append(th(target=self.listen()))
self.jobs.append(th(target=self.brute()))
# Starting them
for job in self.jobs:
th.setDaemon(True)
th.start()