Ejemplo n.º 1
0
	def __init__(self, filename):
		self.name = filename 									# name of file
		self.f = open(filename, "rb")							# Actual underlying file object
		self.data = self.f.read()								# Contents of file
		self.info_hash = bencoding.info_hash(filename)			# Hash of the info section of the torrent file
		(self.length, d) = bencoding.bencode_parse(self.data)	# Python object version of torrent file
		self.dictionary = bencoding.bencode_dict_no_tod(d)		# Python object version of torrent file
		self.trackers = bencoding.trackers(self.dictionary) 	# List of trackers
Ejemplo n.º 2
0
	no_dns = False 
	show_pieces = False 

	argv = sys.argv	
	opts, args = getopt.getopt(argv[1:], "h", ["no-dns", "show-pieces"])	
	
	filename = args[0]

	for o, a in opts:
		if o == "--no-dns":
			no_dns = True 
		elif o == "--show-pieces":
			show_pieces = True 
		elif o == "-h":
			sha_hash = bencoding.info_hash(filename)
			print "SHA-1 Info Hash of file " + filename + ": " + str(sha_hash) + '\n'
		else:
			assert False, "unhandled option"

	l = tracker_request(filename, no_dns)

	print 'List of peers (ip, port):\n'
		
	for addr in l:
		# Default is not to do reverse DNS lookups on the IP addresses given by the tracker
		name = ""
		(ip, port) = addr
		if not no_dns:
			try:
				name, aliases, address = socket.gethostbyaddr(ip)