【问题标题】:how to get the peer list of a torrent using python-libtorrent?如何使用 python-libtorrent 获取 torrent 的对等列表?
【发布时间】:2012-10-29 20:25:53
【问题描述】:

我试过这段代码:

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 bittorrent libtorrent


    【解决方案1】:

    您的 python 代码中似乎有错误。

    打印 lt.peer_info().ip

    该行将构造一个新的 peer_info 对象,然后打印 IP(此时将默认初始化,并包含 0.0.0.0)。

    我相信你想做的是:

    for i in p:
       print i.ip()
    

    即对于洪流中的每个对等点,打印其 IP。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-18
      相关资源
      最近更新 更多