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:
Can you help me?
Thank you so much.
There is no one canonical "peer list". There are the peers you're currently connected to. There is however "every peer in the swarm".
libtorrent can tell you the peers you're connected to, which means they completed a uTP or TCP 3-way handshake.
it typically takes some time to ramp up peer connections. You need to find out about peers, you need to try to connect to them and they need to be up and not have a full peer list. This is why you're not connected to a bunch of peers instantly.
It sounds like you're interested in all peers in the swarm. You are not very likely to find every peer. Peers may not announce to the same trackers, and find each other via PEX or DHT. Many peers are not connectable, and the only way to find them is to have them find you, which they may not be interested in.
Now, it's not clear why you would want peer IPs if you're not interested in downloading the torrent. Given that you aren't, why connect to them at all?
You could simply call get_full_peer_list(), however, that's not available in the python bindings. You could also just announce to the tracker over and over again and collect the resulting IPs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With