from socket import socket from re import search from string import asc

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from socket import socket
from re import search
from string import ascii_letters, digits
from random import choice, randint
from hashlib import md5
def calculateResponse(login, password, cc, sc):
pwmd5 = md5(password).hexdigest()
return md5(
pwmd5+
" "*48+
login+
cc+
sc+
pwmd5).hexdigest()
def getTicket(login,password):
host = "gpcm.gamespy.com"
port = 29900
bufsize = 2048
sock = socket()
sock.connect((host,port))
try:
pass
serverChallenge = search('(?<=\\\\challenge\\\\).*?(?=\\\\)', sock.recv(bufsize)).group(0)
except AttributeError:
return None
clientChallenge = "".join([choice(ascii_letters+digits) for x in xrange(32)])
sock.sendall("\\login\\\\challenge\\%s\\uniquenick\\%s\\response\\%s\\port\\%s\\namespaceid\\1\\id\\1\\final\\"
%(
clientChallenge,
login,
calculateResponse(login, password, clientChallenge, serverChallenge),
randint(0,32767)
))
return search('(?<=\\\\lt\\\\).*?(?=\\\\)', sock.recv(bufsize)).group(0)