Created
May 21, 2014 11:59
-
-
Save refik/679a132d2add3ba46219 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 socket | |
import struct | |
def ip2long(ip): | |
packedIP = socket.inet_aton(ip) | |
return struct.unpack("!I", packedIP)[0] | |
# Handshake | |
message = struct.pack('!qii', 0x41727101980, 0, 1) | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP | |
sock.sendto(message, ('31.172.63.226', 80)) | |
data_raw1 = sock.recvfrom(16) | |
_, _, connection_id = struct.unpack('!iiq', data_raw1[0]) | |
message = struct.pack( | |
'!qii20s20sqqqIIIiHH', | |
connection_id, | |
1, | |
1, | |
'd4ade1a3d935d64603dd5f835ff977d9236a2c59'.decode('hex'), | |
'jngslkvmekrgmal325rw', | |
0, | |
115213797, | |
0, | |
0, | |
ip2long('95.211.93.141'), | |
1, | |
-1, | |
51413, | |
0) | |
sock.sendto(message, ('31.172.63.226', 80)) | |
print 'sent' | |
data_raw2 = sock.recvfrom(1000) | |
length = len(data_raw2[0]) | |
times = (length - 20) / 6 | |
data2 = struct.unpack('!iiiii' + ('iH' * times), data_raw2[0]) | |
ips = data2[5:] | |
for i in range(0, len(ips), 2): | |
ip = ips[i] | |
port = ips[i+1] | |
ip_str = socket.inet_ntoa(struct.pack('!i', ip)) | |
print ip_str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment