#!/usr/bin/python -tt import os import sys from BitTorrent import bencode if len(sys.argv) < 2: print "dump-peers.py datafile destdir-for-logs" sys.exit(1) datfile = sys.argv[1] dstdir = sys.argv[2] if not os.path.exists(dstdir): os.makedirs(dstdir) h = open(datfile, 'rb') ds = h.read() temp = bencode.bdecode(ds) h.close() torrents = temp['allowed'] torrent_dict = {} for t in torrents.keys(): this = torrents[t] name = this['name'] torrent_dict[t] = name peers = temp['peers'] for (k, name) in torrent_dict.items(): fn = '%s/%s' % (dstdir, name) fo = open(fn, 'w') this = peers[k] for d in this.values(): fo.write('%s\n' % d['ip']) fo.flush() fo.close()