python - 如何使用 python-libtorrent 获取 torrent 的对等列表?

标签 python bittorrent libtorrent

我试过这段代码:

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/

相关文章:

php - 来自 rtorrent 的空 xmlrpc 响应

python - 将列表转换为索引和范围 0-1.0

nat - 如何连接到从 bittorrent 获得的对等点

python - 创建新的种子和种子

c# - 通过向下继承树在 C# 中输入“更宽松”

c++ - 适用于 C++、Windows 的 Torrent 库

python - libtorrent python 绑定(bind)中的 torrent_info() 和磁力链接

python - 在 Pyside 中显示 slider 的最小值和最大值

python - 是否有支持同时使用多个独立数据库的 Python ORM?

python - 在 matplotlib 中迭代添加总数未知的子图