Pergunta

Trying to understand / reverse engineer the torrent / tracker conversation. I've managed to get some simple code running that hits up a tracker and prints the response;

>>> import urllib2
>>> import urllib
>>> import binascii

>>> hash = "0221caf96aa3cb94f0f58d458e78b0fc344ad8bf"
>>> url = "http://torrent.ubuntu.com:6969/scrape?info_hash="
>>> url += urllib.quote(binascii.a2b_hex(hash))
>>> f=urllib2.urlopen(url).read()
>>> print f
d5:filesd20:☻!╩∙jú╦ö≡⌡ìEÄx░ⁿ4J╪┐d8:completei4e10:downloadedi0e10:incompletei1e4:name20:dapper-dvd-amd64.isoeee

Per the BitTorrent Tracker Protocol, I expanded the code to try and get a list of peers; the parameters were pulled verbatim from a wireshark sniff (more on that below).

>>> hash = "0221caf96aa3cb94f0f58d458e78b0fc344ad8bf"
>>> url = "http://torrent.ubuntu.com:6969/announce?info_hash="
>>> url += urllib.quote(binascii.a2b_hex(hash))
>>> url +="&peer_id=-UT3320-_vO%21lS%a7%07%876%18%99&port=53965&uploaded=0&downloaded=18874368&left=2850752512&corrupt=0&key=F0E51CD9&event=stopped&numwant=0&compact=1&no_peer_id=1"
>>> f=urllib2.urlopen(url).read()
>>> print f
d8:completei4e10:incompletei2e8:intervali1800e5:peerslee

Using wireshark, I sniffed a "known working" source (the same torrent / info_hash info, but utilizing utorrent), and then sniffed my silly little program; in both instances, the tracker responds with a similar set of data, in the form of 3 packets ([ACK], [PSH, ACK], and [FIN ACK]; but with my python program, I'm not seeing anything past the first [ACK].

Not particularly fluent with networking or packet manipulation, so I'd appreciate any pointers!

Foi útil?

Solução

Totes made a derp here. Just noticed this part of the URL fragment...

&numwant=0

...which, when changed to 1 or higher, FIXES EVERYTHING.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top