Python 3.x 通过stem的多个Tor实例
我正在开发一个脚本,使用stem创建3个Tor实例,从stem教程到《爱的俄罗斯》Python 3.x 通过stem的多个Tor实例,python-3.x,tor,stem,Python 3.x,Tor,Stem,我正在开发一个脚本,使用stem创建3个Tor实例,从stem教程到《爱的俄罗斯》 def print_bootstrap_lines(line): if "Bootstrapped " in line: print(term.format(line, term.Color.BLUE)) def main(): SocksPort=9050 #print(str(SocksPort)) i=0 while i<2
def print_bootstrap_lines(line):
if "Bootstrapped " in line:
print(term.format(line, term.Color.BLUE))
def main():
SocksPort=9050
#print(str(SocksPort))
i=0
while i<2:
tor_process=stem.process.launch_tor_with_config(
config={
'SocksPort':str(SocksPort),
'ControlPort':str(SocksPort+1),
'ExitNodes':'{ru}',
'StrictNodes':'1',},
init_msg_handler=print_bootstrap_lines,
)
SocksPort=SocksPort+2
i=i+1
使用_config函数启动_toru(使用_config函数启动)会使用临时的新TORC文件启动tor,一旦tor实例被终止/停止,该文件就会被删除。 但是我注意到有一个锁文件,就像你中断Linux包管理器更新时的锁文件一样,但是它位于 ~/.tor/lck
因此,在启动新实例之前,请确保等待锁定文件出现,然后从脚本中删除它,多个tor实例将成功创建 只需为每个线程设置不同的DataDiretory即可
self.tor_process = stem.process.launch_tor_with_config(
config={
'SocksPort':str(self.SocksPort),
'ControlPort':str(self.ControlPort),
'ExitNodes':self.ExitNodes,
'StrictNodes':self.StrictNodes,
'DataDirectory': path,
'Log': [
'NOTICE stdout',
'ERR file /tmp/tor_error_log',
],
},
#init_msg_handler=self.print_bootstrap_lines(),
)
self.tor_process = stem.process.launch_tor_with_config(
config={
'SocksPort':str(self.SocksPort),
'ControlPort':str(self.ControlPort),
'ExitNodes':self.ExitNodes,
'StrictNodes':self.StrictNodes,
'DataDirectory': path,
'Log': [
'NOTICE stdout',
'ERR file /tmp/tor_error_log',
],
},
#init_msg_handler=self.print_bootstrap_lines(),
)