我试过这段代码:
import libtorrent as lt
import time
ses = lt.session()
ses.listen_on(6881, 6891)
info = lt.torrent_info('test.torrent')
h = ses.add_torrent({'ti': info, 'save_path': './'})
print 'starting', h.name()
while (not h.is_seed()):
s = h.status()
p = h.get_peer_info()
print lt.peer_info().ip
sys.stdout.flush()
time.sleep(15)
print h.name(), 'complete'
它打印出这个:
starting test.avi
('0.0.0.0', 0)
('0.0.0.0', 0)
.
.
.
所以它没有给我一个对等列表,而是给了我零。我做错了什么吗?
最佳答案
看起来你的 python 代码中有一个错误。
print lt.peer_info().ip
该行将构造一个新的 peer_info 对象,然后打印 IP(此时将默认初始化,并包含 0.0.0.0)。
我相信你想做的是:
for i in p:
print i.ip()
即对于 torrent 中的每个节点,打印其 IP。
关于python - 如何使用 python-libtorrent 获取 torrent 的对等列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13129091/