scripts/get_tracker_peers.py

27 lines
787 B
Python
Executable file

#!/usr/bin/env python3
import bencodepy
import itertools
import requests
def grouper(n, iterable, fillvalue=None):
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
args = [iter(iterable)] * n
return itertools.zip_longest(*args, fillvalue=fillvalue)
for torrent in bencodepy.decode(
requests.get("http://tracker.sbruder.de:6969/scrape").content
)[b"files"].keys():
print("magnet:?xt=urn:btih:" + torrent.hex())
for peer in grouper(
6,
bencodepy.decode(
requests.get(
"http://tracker.sbruder.de:6969/announce",
params={"info_hash": torrent, "peer_id": "acabacabacabacabacab"},
).content
)[b"peers"],
):
print(".".join(map(str, peer[:4])), int.from_bytes(peer[-2:], "big"))