Last active
August 29, 2015 13:57
-
-
Save zhaphod/9870825 to your computer and use it in GitHub Desktop.
Connection reset, by the tracker, upon issuing announce request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import socket | |
import struct | |
import time | |
import urllib | |
import random | |
soc = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
MAX = 65535 | |
PORT = 6881 | |
#I have tried will all the trackers below, but I get the same 10054 issue with announce request | |
host = "tracker.ccc.de" | |
host = "ipv4.tracker.harry.lu" | |
host = "tracker.istole.it" | |
host = "tracker.openbittorrent.com" | |
port = 80 | |
connection_id = 0x41727101980 | |
action = 0 | |
transaction_id = random.randint(256, 4096) | |
msg = struct.pack('!qii', connection_id, action, transaction_id) | |
print msg | |
#connection request/response | |
n = 0 | |
delay = 15 * (2 ** n) | |
while True: | |
soc.sendto(msg, (host, port)) | |
print "setting delay to ", delay, " seconds" | |
soc.settimeout(delay) | |
try: | |
data, address = soc.recvfrom(1024) | |
except socket.timeout: | |
n += 1 | |
delay *= 2 | |
if n > 8: | |
raise RuntimeError("Server not responding, so giving it up") | |
except: | |
raise #some other error so throw it to the user | |
else: | |
print data | |
print address | |
action, ret_transaction_id, connection_id = struct.unpack("!iiq", data) | |
if action != 0 or \ | |
ret_transaction_id != transaction_id: | |
print "Invalid message received from the tracker. Trying again" | |
n = 0 | |
continue | |
else: | |
print "Obtained connection_id ", connection_id | |
break #we got the connection_id | |
soc.close() | |
del(soc) | |
#announce request/response | |
#Tried creating the soc again to see if I don't get the 10054 error. But no luck. | |
soc = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
action = 1 | |
transaction_id = random.randint(256, 4096) | |
#I am using the hash of a specific torrent which is well seeded. | |
#I have tried both quoted and unquoted hashed but I keep getting the 10054 issue | |
quoted_hash = "m%AE%8C%EB%0E%3F%EB%06%8C%96%91%039%D2%EF%E5%D8m%B4%ED" | |
unquoted_hash = urllib.unquote_plus(quoted_hash) | |
info_hash = quoted_hash | |
peer_id = "IMPL_TORRENT__PYTHON" | |
downloaded = 0 | |
left = 121114746 | |
uploaded = 0 | |
event = 0 | |
ip = 0 | |
key = 0 | |
num_want = -1 | |
port = 6881 | |
msg = struct.pack('!qii20s20sqqqiiiih',\ | |
connection_id,\ | |
action,\ | |
transaction_id,\ | |
info_hash,\ | |
peer_id,\ | |
downloaded,\ | |
left,\ | |
uploaded,\ | |
event,\ | |
ip,\ | |
key,\ | |
num_want,\ | |
port) | |
n = 0 | |
delay = 15 * (2 ** n) | |
print "waiting for 20 seconds" | |
time.sleep(5) | |
while True: | |
soc.sendto(msg, (host, port)) | |
print "setting delay to ", delay, " seconds" | |
soc.settimeout(delay) | |
try: | |
data, address = soc.recvfrom(1024) | |
except socket.timeout: | |
n += 1 | |
delay *= 2 | |
if n > 8: | |
raise RuntimeError("Server not responding, so giving it up") | |
except: | |
raise #some other error so throw it to the user | |
else: | |
print data | |
print address | |
action, ret_transaction_id, interval, leechers, seeders = struct.unpack("!iiiii", data) | |
if action != 1 or \ | |
ret_transaction_id != transaction_id: | |
print "Invalid message received from the tracker. Trying again" | |
n = 0 | |
continue | |
else: | |
print "interval ", interval | |
print "leechers ", leechers | |
print "seeders ", seeders | |
break #we got the connection_id | |
soc.close() | |
del(soc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment