2012-10-29 2 views
3

이 코드 시도 :python-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) 
. 
. 
. 

그래서 대신 나에게 그것은 나를 제공하는 피어 목록을 제공 zeros.Am 내가 뭔가 잘못하고?

답변

2

파이썬 코드에 버그가있는 것 같습니다.

인쇄 lt.peer_info().는 IP를 인쇄 한 후 그 라인이 신선한 peer_info 객체를 생성합니다

를 IP 및 (그 시간에 초기화 기본, 그리고 0.0.0.0을 포함 할) . 나는 당신이 원하는 무엇을 믿는

은 다음과 같습니다

for i in p: 
    print i.ip() 

즉 토런트의 각 피어, 자사의 IP를 인쇄 할 수 있습니다.

+0

감사합니다. 그게 내가 원하는 것입니다. – vkefallinos