def set_proxy_settings(self, ltsession, ptype, server=None, auth=None): """ Apply the proxy settings to a libtorrent session. This mechanism changed significantly in libtorrent 1.1.0. """ if LooseVersion(self.get_libtorrent_version()) >= LooseVersion("1.1.0"): settings = ltsession.get_settings() settings["proxy_type"] = ptype settings["proxy_hostnames"] = True settings["proxy_peer_connections"] = True if server and server[0] and server[1]: settings["proxy_hostname"] = server[0] settings["proxy_port"] = int(server[1]) if auth: settings["proxy_username"] = auth[0] settings["proxy_password"] = auth[1] self.set_session_settings(ltsession, settings) else: proxy_settings = lt.proxy_settings() proxy_settings.type = lt.proxy_type(ptype) if server and server[0] and server[1]: proxy_settings.hostname = server[0] proxy_settings.port = int(server[1]) if auth: proxy_settings.username = auth[0] proxy_settings.password = auth[1] proxy_settings.proxy_hostnames = True proxy_settings.proxy_peer_connections = True ltsession.set_proxy(proxy_settings)
def set_proxy_settings(self, ltsession, ptype, server=None, auth=None): """ Apply the proxy settings to a libtorrent session. This mechanism changed significantly in libtorrent 1.1.0. """ if LooseVersion( self.get_libtorrent_version()) >= LooseVersion("1.1.0"): settings = ltsession.get_settings() settings["proxy_type"] = ptype settings["proxy_hostnames"] = True settings["proxy_peer_connections"] = True if server and server[0] and server[1]: settings["proxy_hostname"] = server[0] settings["proxy_port"] = int(server[1]) if auth: settings["proxy_username"] = auth[0] settings["proxy_password"] = auth[1] ltsession.set_settings(settings) else: proxy_settings = lt.proxy_settings() proxy_settings.type = lt.proxy_type(ptype) if server and server[0] and server[1]: proxy_settings.hostname = server[0] proxy_settings.port = int(server[1]) if auth: proxy_settings.username = auth[0] proxy_settings.password = auth[1] proxy_settings.proxy_hostnames = True proxy_settings.proxy_peer_connections = True ltsession.set_proxy(proxy_settings)
def save_conf(self, btn, wfunc, entries): ptype, phost, pport, puser, ppass = entries p = lt.proxy_settings() p.hostname = phost.entry.encode("utf-8") p.port = int(pport.value) p.username = puser.entry.encode("utf-8") p.password = ppass.entry.encode("utf-8") p.type = self.proxy_types[ptype.text] wfunc(p)
def start(self): cherrypy.process.plugins.Monitor.start(self) self.bus.log('[Downloader] Starting session') self.session = libtorrent.session() self.session.set_alert_mask(libtorrent.alert.category_t.error_notification | libtorrent.alert.category_t.status_notification | libtorrent.alert.category_t.storage_notification) # Session settings session_settings = self.session.settings() session_settings.announce_to_all_tiers = True session_settings.announce_to_all_trackers = True session_settings.connection_speed = 100 session_settings.peer_connect_timeout = 2 session_settings.rate_limit_ip_overhead = True session_settings.request_timeout = 5 session_settings.torrent_connect_boost = 100 if self.torrent_config['max_download_rate'] > 0: session_settings.download_rate_limit = self.torrent_config['max_download_rate'] * 1024 if self.torrent_config['max_upload_rate'] > 0: session_settings.upload_rate_limit = self.torrent_config['max_upload_rate'] * 1024 self.session.set_settings(session_settings) # Proxy settings proxy_settings = libtorrent.proxy_settings() if self.torrent_config['proxy_type'] == 'SOCKS5': proxy_settings.hostname = self.torrent_config['proxy_host'] proxy_settings.port = self.torrent_config['proxy_port'] if self.torrent_config['proxy_user']: proxy_settings.type = libtorrent.proxy_type.socks5_pw proxy_settings.username = self.torrent_config['proxy_user'] proxy_settings.password = self.torrent_config['proxy_password'] else: proxy_settings.type = libtorrent.proxy_type.socks5 self.session.set_proxy(proxy_settings) # Encryption settings encryption_settings = libtorrent.pe_settings() encryption_settings.out_enc_policy = libtorrent.enc_policy(libtorrent.enc_policy.forced) encryption_settings.in_enc_policy = libtorrent.enc_policy(libtorrent.enc_policy.forced) encryption_settings.allowed_enc_level = libtorrent.enc_level.both encryption_settings.prefer_rc4 = True self.session.set_pe_settings(encryption_settings) self.session.start_dht() self.session.start_lsd() if self.torrent_config['upnp_natpmp_enabled']: self.session.start_upnp() self.session.start_natpmp() self.session.listen_on(self.torrent_config['port'], self.torrent_config['port'])
def set_proxy_settings(self, ltsession, ptype, server=None, auth=None): proxy_settings = lt.proxy_settings() proxy_settings.type = lt.proxy_type(ptype) if server: proxy_settings.hostname = server[0] proxy_settings.port = server[1] if auth: proxy_settings.username = auth[0] proxy_settings.password = auth[1] proxy_settings.proxy_hostnames = True proxy_settings.proxy_peer_connections = True if ltsession is not None: ltsession.set_proxy(proxy_settings) else: # only apply the proxy settings to normal libtorrent session (with hops = 0) self.ltsessions[0].set_proxy(proxy_settings)
def configure_proxy(self, proxy_type=None, proxy_host=None, proxy_port=None): proxy_type = proxy_type or self.proxy_type proxy_host = proxy_host or self.proxy_host proxy_port = proxy_port or self.proxy_port if proxy_port and proxy_host: proxy_settings = lt.proxy_settings() proxy_settings.type = proxy_type proxy_settings.hostname = proxy_host proxy_settings.port = proxy_port self.session.set_proxy(proxy_settings) self.session.set_dht_proxy(proxy_settings) self.session.set_peer_proxy(proxy_settings) self.session.set_tracker_proxy(proxy_settings) self.session.set_web_seed_proxy(proxy_settings)
def __init__(self, port_min=6881, port_max=6891, max_download_rate=0, max_upload_rate=0, save_path='.', allocation_mode='compact', proxy_host='', alert_mask=0xfffffff, verbose=False, status_update_interval=0.25, bootstrap_node='router.bittorrent.com', bootstrap_port=6881): """Initialize libtorrent session with supplied parameters. :param port: Listening port. :type port: int :param max_download_rate: The maximum download rate given in kB/s. A value of 0 means the download rate is unbounded. :type max_download_rate: int or float :param max_upload_rate: The maximum upload rate given in kB/s. A value of 0 means the upload rate is unbounded. :type max_upload_rate: int or float :param save_path: The path where the downloaded file/folder should be placed. :type save_path: str :param allocation_mode: Set the mode used for allocating the downloaded files on disk. Possible options include 'full' and 'compact'. :type allocation_mode: str :param proxy_host: Sets a HTTP proxy host and port, separate by a colon. :type proxy_host: str :param alert_mask: Changes the mask of which alerts to receive. By default only errors are reported. It is a bitmask where each bit represents a category of alerts. :type alert_mask: int (bitmask) :param verbose: Indicate if actions should be made verbosely or not. :type verbose: bool :param status_update_interval: The interval at which the session should update the status dictionary with current information about the torrents it is managing. :type status_update_interval: int or float :param bootstrap_node: Boostrap DHT router to connect to. :type boostrap_node: str :param bootstrap_port: Port of boostrap DHT router to connect to. :type bootstrap_port: int """ if port_min < 0 or port_min > 65525 or not isinstance(port_min, int): raise StorjTorrentError( 'port_min must be an integer value between 0 and 65525.') if port_max < port_min or port_max > 65525 or not isinstance(port_max, int): raise StorjTorrentError( ('port_max must be an integer value greater than port_min and' 'less than 65525.')) if max_download_rate <= 0: self.max_download_rate = -1 else: self.max_download_rate = 1000 * max_download_rate if max_upload_rate <= 0: self.max_upload_rate = -1 else: self.max_upload_rate = 1000 * max_upload_rate self.status_update_interval = status_update_interval self.save_path = os.path.abspath(save_path) self.verbose = verbose self.compact_allocation = allocation_mode == 'compact' self.settings = lt.session_settings() self.settings.user_agent = 'Storj/' + __version__ self.session = lt.session() self.session.set_download_rate_limit(self.max_download_rate) self.session.set_upload_rate_limit(self.max_upload_rate) self.session.listen_on(port_min, port_max) self.session.set_settings = self.settings self.session.set_alert_mask(alert_mask) self.session.add_dht_router(bootstrap_node, bootstrap_port) if proxy_host is not '': proxy_settings = lt.proxy_settings() proxy_settings.type = lt.proxy_type.http proxy_settings.hostname = proxy_host.split(':')[0] proxy_settings.port = int(proxy_host.split(':')[1]) self.session.set_proxy(proxy_settings) self.handles = [] self._status = {'torrents': {}, 'alerts': {}} self.alive = True self.subthread = IntervalTimer(status_update_interval, self._watch_torrents) self.subthread.start()
def main(): from optparse import OptionParser parser = OptionParser() parser.add_option('-p', '--port', type='int', help='set listening port') parser.add_option( '-d', '--max-download-rate', type='float', help='the maximum download rate given in kB/s. 0 means infinite.') parser.add_option( '-u', '--max-upload-rate', type='float', help='the maximum upload rate given in kB/s. 0 means infinite.') parser.add_option( '-s', '--save-path', type='string', help='the path where the downloaded file/folder should be placed.') parser.add_option( '-r', '--proxy-host', type='string', help='sets HTTP proxy host and port (separated by \':\')') parser.set_defaults(port=6881, max_download_rate=0, max_upload_rate=0, save_path='.', proxy_host='') (options, args) = parser.parse_args() if options.port < 0 or options.port > 65525: options.port = 6881 options.max_upload_rate *= 1000 options.max_download_rate *= 1000 if options.max_upload_rate <= 0: options.max_upload_rate = -1 if options.max_download_rate <= 0: options.max_download_rate = -1 settings = lt.session_settings() settings.user_agent = 'python_client/' + lt.version ses = lt.session() ses.set_download_rate_limit(int(options.max_download_rate)) ses.set_upload_rate_limit(int(options.max_upload_rate)) ses.listen_on(options.port, options.port + 10) ses.set_settings(settings) ses.set_alert_mask(0xfffffff) if options.proxy_host != '': ps = lt.proxy_settings() ps.type = lt.proxy_type.http ps.hostname = options.proxy_host.split(':')[0] ps.port = int(options.proxy_host.split(':')[1]) ses.set_proxy(ps) handles = [] alerts = [] for f in args: atp = {} atp["save_path"] = options.save_path atp["storage_mode"] = lt.storage_mode_t.storage_mode_sparse atp["paused"] = False atp["auto_managed"] = True atp["duplicate_is_error"] = True if f.startswith('magnet:') or f.startswith('http://') or f.startswith( 'https://'): atp["url"] = f else: info = lt.torrent_info(f) print('Adding \'%s\'...' % info.name()) try: atp["resume_data"] = open( os.path.join(options.save_path, info.name() + '.fastresume'), 'rb').read() except: pass atp["ti"] = info h = ses.add_torrent(atp) handles.append(h) h.set_max_connections(60) h.set_max_uploads(-1) if os.name == 'nt': console = WindowsConsole() else: console = UnixConsole() alive = True while alive: console.clear() out = '' for h in handles: if h.has_metadata(): name = h.get_torrent_info().name()[:40] else: name = '-' out += 'name: %-40s\n' % name s = h.status() if s.state != lt.torrent_status.seeding: state_str = ['queued', 'checking', 'downloading metadata', \ 'downloading', 'finished', 'seeding', \ 'allocating', 'checking fastresume'] out += state_str[s.state] + ' ' out += '%5.4f%% ' % (s.progress * 100) out += progress_bar(s.progress, 49) out += '\n' out += 'total downloaded: %d Bytes\n' % s.total_done out += 'peers: %d seeds: %d distributed copies: %d\n' % \ (s.num_peers, s.num_seeds, s.distributed_copies) out += '\n' out += 'download: %s/s (%s) ' \ % (add_suffix(s.download_rate), add_suffix(s.total_download)) out += 'upload: %s/s (%s) ' \ % (add_suffix(s.upload_rate), add_suffix(s.total_upload)) if s.state != lt.torrent_status.seeding: out += 'info-hash: %s\n' % h.info_hash() out += 'next announce: %s\n' % s.next_announce out += 'tracker: %s\n' % s.current_tracker write_line(console, out) print_peer_info(console, h.get_peer_info()) print_download_queue(console, h.get_download_queue()) if s.state != lt.torrent_status.seeding: try: out = '\n' fp = h.file_progress() ti = h.get_torrent_info() for f, p in zip(ti.files(), fp): out += progress_bar(p / float(f.size), 20) out += ' ' + f.path + '\n' write_line(console, out) except: pass write_line(console, 76 * '-' + '\n') write_line(console, '(q)uit), (p)ause), (u)npause), (r)eannounce\n') write_line(console, 76 * '-' + '\n') while 1: a = ses.pop_alert() if not a: break alerts.append(a) if len(alerts) > 8: del alerts[:len(alerts) - 8] for a in alerts: if type(a) == str: write_line(console, a + '\n') else: write_line(console, a.message() + '\n') c = console.sleep_and_input(0.5) if not c: continue if c == 'r': for h in handles: h.force_reannounce() elif c == 'q': alive = False elif c == 'p': for h in handles: h.pause() elif c == 'u': for h in handles: h.resume() ses.pause() for h in handles: if not h.is_valid() or not h.has_metadata(): continue data = lt.bencode(h.write_resume_data()) open( os.path.join(options.save_path, h.get_torrent_info().name() + '.fastresume'), 'wb').write(data)
def main(): from optparse import OptionParser parser = OptionParser() parser.add_option('-p', '--port', type='int', help='set listening port') parser.add_option('-d', '--max-download-rate', type='float', help='the maximum download rate given in kB/s. 0 means infinite.') parser.add_option('-u', '--max-upload-rate', type='float', help='the maximum upload rate given in kB/s. 0 means infinite.') parser.add_option('-s', '--save-path', type='string', help='the path where the downloaded file/folder should be placed.') parser.add_option('-a', '--allocation-mode', type='string', help='sets mode used for allocating the downloaded files on disk. Possible options are [full | compact]') parser.add_option('-r', '--proxy-host', type='string', help='sets HTTP proxy host and port (separated by \':\')') parser.set_defaults( port=6881 , max_download_rate=0 , max_upload_rate=0 , save_path='./' , allocation_mode='compact' , proxy_host='' ) (options, args) = parser.parse_args() if options.port < 0 or options.port > 65525: options.port = 6881 options.max_upload_rate *= 1000 options.max_download_rate *= 1000 if options.max_upload_rate <= 0: options.max_upload_rate = -1 if options.max_download_rate <= 0: options.max_download_rate = -1 compact_allocation = options.allocation_mode == 'compact' settings = lt.session_settings() settings.user_agent = 'python_client/' + lt.version ses = lt.session() ses.set_download_rate_limit(int(options.max_download_rate)) ses.set_upload_rate_limit(int(options.max_upload_rate)) ses.listen_on(options.port, options.port + 10) ses.set_settings(settings) ses.set_alert_mask(0xfffffff) if options.proxy_host != '': ps = lt.proxy_settings() ps.type = lt.proxy_type.http ps.hostname = options.proxy_host.split(':')[0] ps.port = int(options.proxy_host.split(':')[1]) ses.set_proxy(ps) handles = [] alerts = [] for f in args: atp = {} atp["save_path"] = options.save_path atp["storage_mode"] = lt.storage_mode_t.storage_mode_sparse atp["paused"] = False atp["auto_managed"] = True atp["duplicate_is_error"] = True if f.startswith('magnet:') or f.startswith('http://') or f.startswith('https://'): atp["url"] = f else: e = lt.bdecode(open(f, 'rb').read()) info = lt.torrent_info(e) print('Adding \'%s\'...' % info.name()) try: atp["resume_data"] = open(os.path.join(options.save_path, info.name() + '.fastresume'), 'rb').read() except: pass atp["ti"] = info h = ses.add_torrent(atp) handles.append(h) h.set_max_connections(60) h.set_max_uploads(-1) if os.name == 'nt': console = WindowsConsole() else: console = UnixConsole() alive = True while alive: console.clear() out = '' for h in handles: if h.has_metadata(): name = h.get_torrent_info().name()[:40] else: name = '-' out += 'name: %-40s\n' % name s = h.status() if s.state != lt.torrent_status.seeding: state_str = ['queued', 'checking', 'downloading metadata', \ 'downloading', 'finished', 'seeding', \ 'allocating', 'checking fastresume'] out += state_str[s.state] + ' ' out += '%5.4f%% ' % (s.progress*100) out += progress_bar(s.progress, 49) out += '\n' out += 'total downloaded: %d Bytes\n' % s.total_done out += 'peers: %d seeds: %d distributed copies: %d\n' % \ (s.num_peers, s.num_seeds, s.distributed_copies) out += '\n' out += 'download: %s/s (%s) ' \ % (add_suffix(s.download_rate), add_suffix(s.total_download)) out += 'upload: %s/s (%s) ' \ % (add_suffix(s.upload_rate), add_suffix(s.total_upload)) if s.state != lt.torrent_status.seeding: out += 'info-hash: %s\n' % h.info_hash() out += 'next announce: %s\n' % s.next_announce out += 'tracker: %s\n' % s.current_tracker write_line(console, out) print_peer_info(console, h.get_peer_info()) print_download_queue(console, h.get_download_queue()) if s.state != lt.torrent_status.seeding: try: out = '\n' fp = h.file_progress() fp = 0 ti = h.get_torrent_info() for f,p in zip(ti.files(), fp): out += progress_bar(p / f.size, 20) out += ' ' + f.path + '\n' write_line(console, out) except: pass write_line(console, 76 * '-' + '\n') write_line(console, '(q)uit), (p)ause), (u)npause), (r)eannounce\n') write_line(console, 76 * '-' + '\n') while 1: a = ses.pop_alert() if not a: break alerts.append(a) if len(alerts) > 8: del alerts[:len(alerts) - 8] for a in alerts: if type(a) == str: write_line(console, a + '\n') else: write_line(console, a.message() + '\n') c = console.sleep_and_input(0.5) if not c: continue if c == 'r': for h in handles: h.force_reannounce() elif c == 'q': alive = False elif c == 'p': for h in handles: h.pause() elif c == 'u': for h in handles: h.resume() ses.pause() for h in handles: if not h.is_valid() or not h.has_metadata(): continue data = lt.bencode(h.write_resume_data()) open(os.path.join(options.save_path, h.get_torrent_info().name() + '.fastresume'), 'wb').write(data)
def proxy_setup(proxy_host): proxy_settings = lt.proxy_settings() proxy_settings.type = lt.proxy_type.http hostname, port = proxy_host.split(':') proxy_settings.hostname, proxy_settings.port = hostname, int(port) return proxy_settings
def main(): from optparse import OptionParser parser = OptionParser() parser.add_option("-p", "--port", type="int", help="set listening port") parser.add_option( "-d", "--max-download-rate", type="float", help="the maximum download rate given in kB/s. 0 means infinite." ) parser.add_option( "-u", "--max-upload-rate", type="float", help="the maximum upload rate given in kB/s. 0 means infinite." ) parser.add_option( "-s", "--save-path", type="string", help="the path where the downloaded file/folder should be placed." ) parser.add_option( "-a", "--allocation-mode", type="string", help="sets mode used for allocating the downloaded files on disk. Possible options are [full | compact]", ) parser.add_option("-r", "--proxy-host", type="string", help="sets HTTP proxy host and port (separated by ':')") parser.set_defaults( port=6881, max_download_rate=0, max_upload_rate=0, save_path="./", allocation_mode="compact", proxy_host="" ) (options, args) = parser.parse_args() if options.port < 0 or options.port > 65525: options.port = 6881 options.max_upload_rate *= 1000 options.max_download_rate *= 1000 if options.max_upload_rate <= 0: options.max_upload_rate = -1 if options.max_download_rate <= 0: options.max_download_rate = -1 compact_allocation = options.allocation_mode == "compact" settings = lt.session_settings() settings.user_agent = "python_client/" + lt.version ses = lt.session() ses.set_download_rate_limit(int(options.max_download_rate)) ses.set_upload_rate_limit(int(options.max_upload_rate)) ses.listen_on(options.port, options.port + 10) ses.set_settings(settings) ses.set_alert_mask(0xFFFFFFF) if options.proxy_host != "": ps = lt.proxy_settings() ps.type = lt.proxy_type.http ps.hostname = options.proxy_host.split(":")[0] ps.port = int(options.proxy_host.split(":")[1]) ses.set_proxy(ps) handles = [] alerts = [] for f in args: e = lt.bdecode(open(f, "rb").read()) info = lt.torrent_info(e) print("Adding '%s'..." % info.name()) atp = {} try: atp["resume_data"] = open(os.path.join(options.save_path, info.name() + ".fastresume"), "rb").read() except: pass atp["ti"] = info atp["save_path"] = options.save_path atp["storage_mode"] = lt.storage_mode_t.storage_mode_sparse atp["paused"] = False atp["auto_managed"] = True atp["duplicate_is_error"] = True h = ses.add_torrent(atp) handles.append(h) h.set_max_connections(60) h.set_max_uploads(-1) if os.name == "nt": console = WindowsConsole() else: console = UnixConsole() alive = True while alive: console.clear() out = "" for h in handles: if h.has_metadata(): name = h.get_torrent_info().name()[:40] else: name = "-" out += "name: %-40s\n" % name s = h.status() if s.state != lt.torrent_status.seeding: state_str = [ "queued", "checking", "downloading metadata", "downloading", "finished", "seeding", "allocating", "checking fastresume", ] out += state_str[s.state] + " " out += "%5.4f%% " % (s.progress * 100) out += progress_bar(s.progress, 49) out += "\n" out += "total downloaded: %d Bytes\n" % s.total_done out += "peers: %d seeds: %d distributed copies: %d\n" % (s.num_peers, s.num_seeds, s.distributed_copies) out += "\n" out += "download: %s/s (%s) " % (add_suffix(s.download_rate), add_suffix(s.total_download)) out += "upload: %s/s (%s) " % (add_suffix(s.upload_rate), add_suffix(s.total_upload)) if s.state != lt.torrent_status.seeding: out += "info-hash: %s\n" % h.info_hash() out += "next announce: %s\n" % s.next_announce out += "tracker: %s\n" % s.current_tracker write_line(console, out) print_peer_info(console, h.get_peer_info()) print_download_queue(console, h.get_download_queue()) if True and s.state != lt.torrent_status.seeding: out = "\n" fp = h.file_progress() ti = h.get_torrent_info() for f, p in zip(ti.files(), fp): out += progress_bar(p / f.size, 20) out += " " + f.path + "\n" write_line(console, out) write_line(console, 76 * "-" + "\n") write_line(console, "(q)uit), (p)ause), (u)npause), (r)eannounce\n") write_line(console, 76 * "-" + "\n") while 1: a = ses.pop_alert() if not a: break alerts.append(a) if len(alerts) > 8: del alerts[: len(alerts) - 8] for a in alerts: if type(a) == str: write_line(console, a + "\n") else: write_line(console, a.message() + "\n") c = console.sleep_and_input(0.5) if not c: continue if c == "r": for h in handles: h.force_reannounce() elif c == "q": alive = False elif c == "p": for h in handles: h.pause() elif c == "u": for h in handles: h.resume() ses.pause() for h in handles: if not h.is_valid() or not h.has_metadata(): continue data = lt.bencode(h.write_resume_data()) open(os.path.join(options.save_path, h.get_torrent_info().name() + ".fastresume"), "wb").write(data)
def checkseed(ip_table2): from optparse import OptionParser parser = OptionParser() parser.add_option('-p', '--port', type='int', help='set listening port') parser.add_option('-d', '--max-download-rate', type='float', help='the maximum download rate given in kB/s. 0 means infinite.') parser.add_option('-u', '--max-upload-rate', type='float', help='the maximum upload rate given in kB/s. 0 means infinite.') parser.add_option('-s', '--save-path', type='string', help='the path where the downloaded file/folder should be placed.') parser.add_option('-a', '--allocation-mode', type='string', help='sets mode used for allocating the downloaded files on disk. Possible options are [full | compact]') parser.add_option('-r', '--proxy-host', type='string', help='sets HTTP proxy host and port (separated by \':\')') parser.set_defaults( port=6881 , max_download_rate=0 , max_upload_rate=0 , save_path='.' , allocation_mode='compact' , proxy_host='' ) (options, args) = parser.parse_args() if options.port < 0 or options.port > 65525: options.port = 6881 options.max_upload_rate *= 1000 options.max_download_rate *= 1000 if options.max_upload_rate <= 0: options.max_upload_rate = -1 if options.max_download_rate <= 0: options.max_download_rate = -1 compact_allocation = options.allocation_mode == 'compact' settings = lt.session_settings() settings.user_agent = 'python_client/' + lt.version ses = lt.session() ses.set_download_rate_limit(int(options.max_download_rate)) ses.set_upload_rate_limit(int(options.max_upload_rate)) ses.listen_on(options.port, options.port + 10) ses.set_settings(settings) ses.set_alert_mask(0xfffffff) if options.proxy_host != '': ps = lt.proxy_settings() ps.type = lt.proxy_type.http ps.hostname = options.proxy_host.split(':')[0] ps.port = int(options.proxy_host.split(':')[1]) ses.set_proxy(ps) magnet=raw_input("Please enter magnet link ") rawdata = magnet2torrent(magnet) di=lt.bdecode(rawdata) info = lt.torrent_info(di) atp = {} atp["save_path"] = options.save_path atp["storage_mode"] = lt.storage_mode_t.storage_mode_sparse atp["paused"] = False atp["auto_managed"] = True atp["duplicate_is_error"] = True handles = [] print('Adding \'%s\'...' % info.name()) atp["ti"] = info h = ses.add_torrent(atp) handles.append(h) torrent_inf=h.get_torrent_info() trackers = torrent_inf.trackers() x=1 i=0 while(x==1): peers=h.get_peer_info() for p in peers: if p.ip not in ip_table2: if p.flags & lt.peer_info.seed : #this peer is a seed ip_table2.append(p.ip) i=i+1 print i if i>3: x=0 for el in ip_table2: print el