In [170]:
import socket, array, struct, sys
from random import randrange

In [171]:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

In [172]:
tracker = 'open.demonii.com'
port = 1337
info = (tracker, port)

In [176]:
sock.connect(info)

connection_id = 0x41727101980
action = 0
transaction_id = randrange(1,65535)


request = struct.pack('>QLL',connection_id, action, transaction_id)

sent = sock.send(request)
response = sock.recv(68)

In [177]:
action,transaction_id,connection_id=struct.unpack(">LLQ",response)

In [178]:
print(action)
print(transaction_id)
print(connection_id)
print(sys.getsizeof(response))


0
842
10895480635938593698
49

In [159]:
# 0       64-bit integer  connection_id
# 8       32-bit integer  action          1 // announce
# 12      32-bit integer  transaction_id
# 16      20-byte string  info_hash
# 36      20-byte string  peer_id
# 56      64-bit integer  downloaded
# 64      64-bit integer  left
# 72      64-bit integer  uploaded
# 80      32-bit integer  event           0 // 0: none; 1: completed; 2: started; 3: stopped
# 84      32-bit integer  IP address      0 // default
# 88      32-bit integer  key
# 92      32-bit integer  num_want        -1 // default
# 96      16-bit integer  port
# 98
cid = connection_id
action = 1
tid = transaction_id
info_hash

struct.pack('>QLL20s20sQQQLLLLH',)


Out[159]:
4497486125440

In [181]:



---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-181-3819c6e3a77a> in <module>()
----> 1 socket.getaddrinfo('colle-mac')

TypeError: Required argument 'port' (pos 2) not found

In [ ]: