I search to retrieve the peer's IP of a torrent using libtorrent with Python. I try with the code :
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()
for i in p:
print i.ip
print "\n\n"
sys.stdout.flush()
time.sleep(1)
print h.name(), 'complete'
It works more or less but I have two problems:
- The torrent are downloaded.
- The loop are executed dozens times before I receive one peer list.
Can you help me?
Thank you so much.