· 7 years ago · Jan 10, 2019, 05:42 PM
1import time
2import random
3import requests
4from selenium import webdriver
5import datetime
6from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
7import os
8import MySQLdb as mdb
9import traceback
10import sys
11from pyvirtualdisplay import Display
12from PIL import Image
13from python_anticaptcha import AnticaptchaClient, FunCaptchaTask, Proxy
14
15#-------- DEFINITIONS --------
16#vote url
17VoteURL = "https://www.gtop100.com/topsites/Ragnarok-Online/sitedetails/Forsaken-Ragnarok-Online-89530?vote=1"
18
19#referer URL
20ReferrerURL = "http://forsaken-ro.net/vote.php"
21
22#2captcha API Key
23global TwoCaptchaAPIKey
24TwoCaptchaAPIKey = "f118bc23fabde601bd3df540707f65f8"
25
26#AntiCaptcha API Key
27global AntiCaptchaAPIKey
28AntiCaptchaAPIKey = "e4c20c17a260fb72ac05053d802ca70c"
29
30#2Captcha Input API URL
31TwoCaptchaInputAPIURL = "http://2captcha.com/in.php?key={}&method=funcaptcha&publickey={}&pageurl={}&proxy={}&proxytype={}"
32
33#2Captcha Output API URL
34TwoCaptchaOutputAPIURL = "http://2captcha.com/res.php?key={}&action=get&id={}"
35
36#Set My IP Address
37HomeIP = "96.237.150.137"
38
39#Proxylist 1, Backconnect Proxies
40ProxyList1 = []
41with open("../Tools/proxy_list1.txt") as f:
42 ProxyList1 = f.readlines()
43
44#Useragent List
45UserAgentList = []
46with open("../Tools/user_agent_list.txt") as f:
47 UserAgentList = f.readlines()
48
49#Pick which proxy list the box will use
50global ProxyList;
51ProxyList = ProxyList1;
52
53#Driver Timeout
54global time_to_wait
55DriverTimeout = 120
56
57#Create Date for saving file
58Now = datetime.datetime.now()
59Date = Now.strftime("%Y_%m_%d ")
60
61#IP Log File
62IPLogFileName = "IPs_"+Date
63IPLogFileName = IPLogFileName.replace(" ", "")
64
65#DB Login Info
66DB_IP = "dev01.forsaken-ro.net"
67DB_User = "rosefox911"
68DB_Password = "jmead"
69DB_Database = "GTop100"
70
71#Create database if it doesn't exist
72DB = mdb.connect(DB_IP, DB_User, DB_Password)
73Cursor = DB.cursor()
74Cursor.execute("CREATE DATABASE IF NOT EXISTS "+ DB_Database + ";")
75DB.commit()
76DB.close()
77
78#Create IPs table in SQLite if it doesn't exist
79DB = mdb.connect(DB_IP, DB_User, DB_Password, DB_Database)
80Cursor = DB.cursor()
81Cursor.execute("CREATE TABLE IF NOT EXISTS " + IPLogFileName + "(IP VARCHAR(20) PRIMARY KEY);")
82DB.commit()
83DB.close()
84
85if (sys.platform != "win32" and ProxyList1[0].startswith('socks5://')):
86 print("Starting display.")
87 display = Display(visible=0, size=(800, 600))
88 display.start()
89
90#-------- DEFINITIONS --------
91
92#Selects proxy
93def SelectProxy():
94 print("Picking proxy.")
95 Proxy = random.choice(ProxyList);
96 Proxy = Proxy.replace('\n', '')
97 print("Using proxy: " + Proxy)
98 return Proxy
99
100#Select useragent
101def SelectUserAgent():
102 print("Picking user agent.")
103 UserAgent = random.choice(UserAgentList)
104 UserAgent = UserAgent.replace('\n', '')
105 print("Using user agent: " + UserAgent)
106 return UserAgent
107
108#Creates driver
109def CreateDriver(Proxy, UserAgent):
110 print("Creating driver.")
111
112 ChromeOptions = webdriver.ChromeOptions()
113 ChromeOptions.add_argument('--proxy-server=%s' % Proxy)
114 ChromeOptions.add_argument('--user-agent=%s' % UserAgent)
115 WindowsXCoord = 600
116 WindowsYCoord = 800
117 ChromeOptions.add_argument('window-size=' + str(WindowsXCoord) + "x" + str(WindowsYCoord))
118 ChromeOptions.add_experimental_option("prefs",{'profile.managed_default_content_settings.javascript': 1})
119 #Prefs = {"profile.managed_default_content_settings.images": 2}
120 #ChromeOptions.add_experimental_option("prefs", Prefs)
121
122 #Unix system, with socks5 proxies.
123 if (sys.platform != "win32" and ProxyList1[0].startswith('socks5://')):
124 print("Unix System being used, proceeding accordingly.")
125 ChromeOptions.binary_location = '/usr/bin/google-chrome-unstable'
126 ChromeOptions.add_argument("--disable-extensions")
127
128 #Unix system, with http proxies.
129 if (sys.platform != "win32" and not ProxyList1[0].startswith('socks5://')):
130 print("Unix System being used, proceeding accordingly.")
131 ChromeOptions.binary_location = '/usr/bin/google-chrome-unstable'
132 ChromeOptions.add_argument("--disable-extensions")
133 ChromeOptions.add_argument('--headless')
134
135 global driver
136 driver = webdriver.Chrome(chrome_options=ChromeOptions)
137 driver.set_page_load_timeout(DriverTimeout)
138
139#Navigate Website
140def NavigateReferrer():
141 print("Navigating referrer link.")
142 driver.find_element_by_name("gtop100").click()
143 time.sleep(10)
144
145#Grabs the IP from Referrer to confirm we haven't votted from it today
146def GrabIPFromReferrer():
147 print("Going to and grabbing IP from referrer link.")
148 driver.get(ReferrerURL)
149 CurrentIP = driver.find_element_by_name("ip").text
150 return CurrentIP
151
152#Checks if the IP has been used already today
153def CheckIfIPUsedToday(CurrentIP):
154 DB = mdb.connect(DB_IP, DB_User, DB_Password, DB_Database)
155 Cursor = DB.cursor()
156 Cursor.execute("SELECT EXISTS(SELECT 1 FROM " + IPLogFileName + " WHERE IP='" + CurrentIP + "')")
157 Results = Cursor.fetchall()
158
159 DB.close()
160 if (Results == ((1L,),)):
161 print("IP: " + CurrentIP + " was used today.")
162 return True
163 else:
164 print("IP: " + CurrentIP + " was not used today.")
165 DB = mdb.connect(DB_IP, DB_User, DB_Password, DB_Database)
166 Cursor = DB.cursor()
167 Cursor.execute("REPLACE INTO " + IPLogFileName + " (ip) VALUES ('" + CurrentIP + "');")
168 DB.commit()
169 DB.close()
170 return False
171
172#Get Solution from 2captcha.com
173def GetSolutionFrom2Captcha(ProxyInfo, PKKey, UserAgent):
174 CaptchaAnswer = ""
175 print("Solving Captcha.")
176
177 CaptchaSession = requests.Session()
178
179 if(ProxyInfo.startswith('socks5://')):
180 print("Socks5 proxy being used.")
181 proxy = {'http': ProxyInfo.replace("socks5://","http://"), 'https': ProxyInfo.replace("socks5://","https://")}
182 CaptchaID = CaptchaSession.post(TwoCaptchaInputAPIURL.format( TwoCaptchaAPIKey, PKKey, VoteURL, ProxyInfo, "SOCKS5"), proxies=proxy).text.split('|')[1]
183 else:
184 print("HTTP proxy being used.")
185 proxy = {'http': 'http://' + ProxyInfo, 'https': 'https://' + ProxyInfo}
186 Send_Captcha_Post = CaptchaSession.post(TwoCaptchaInputAPIURL.format(TwoCaptchaAPIKey, PKKey, VoteURL, ProxyInfo, "HTTP"), proxies=proxy).text
187 Send_Captcha_Post.split('|')
188 print("Recieved Reply: " + str(Send_Captcha_Post))
189 CaptchaID = Send_Captcha_Post.replace("OK|", "")
190 print("Captcha ID is : " + CaptchaID)
191
192 recaptcha_answer = CaptchaSession.get(TwoCaptchaOutputAPIURL.format(TwoCaptchaAPIKey, CaptchaID), proxies=proxy).text
193 while 'CAPCHA_NOT_READY' in recaptcha_answer:
194 print("Waiting for Solution.")
195 time.sleep(5)
196 recaptcha_answer = CaptchaSession.get(TwoCaptchaOutputAPIURL.format(TwoCaptchaAPIKey, CaptchaID),proxies=proxy).text
197 recaptcha_answer = recaptcha_answer.split('|')[1]
198 return recaptcha_answer
199
200#Get Solution from AntiCaptcha
201def GetSolutionFromAntiCaptcha(ProxyInfo, PKKey, UserAgent):
202 print("Grabbing Solution from AntiCaptcha.")
203 ProxyInfo = "http://" + ProxyInfo
204 ProxyToUse = Proxy.parse_url(ProxyInfo)
205
206 Client = AnticaptchaClient(AntiCaptchaAPIKey)
207 Task = FunCaptchaTask(VoteURL, PKKey, proxy=ProxyToUse, user_agent=UserAgent)
208 Job = Client.createTask(Task)
209 Job.join()
210 Answer = Job.get_token_response()
211 return Answer
212
213#Grabbing PK Key
214def GrabPKKey():
215 print("Grabbing PK Key.")
216 PKKey = driver.find_element_by_id("FunCaptcha-Token").get_attribute("value")
217 PKKey = PKKey.split("pk=")[1]
218 PKKey = PKKey.split("|")[0]
219 return PKKey
220
221#Enter Solution into Field
222def EnterSolutionIntoField(Solution):
223 print("Entering solution into response field.")
224 Command = "document.getElementById('FunCaptcha-Token').value='" + Solution + "';"
225 driver.execute_script(Command)
226 time.sleep(5)
227
228#Click Vote Button
229def ClickVoteButton(CurrentIP):
230 print("Clicking vote button.")
231 driver.switch_to.default_content()
232 driver.find_element_by_id("votebutton").click()
233 print("Vote Complete.")
234 time.sleep(10)
235 AddIPToSQL(CurrentIP)
236
237#Add used IP to MySQL
238def AddIPToSQL(CurrentIP):
239 print("Adding IP to SQL DB.")
240 DB = mdb.connect(DB_IP, DB_User, DB_Password, DB_Database)
241 Cursor = DB.cursor()
242 Cursor.execute("REPLACE INTO " + IPLogFileName + " (ip) VALUES ('" + CurrentIP + "');")
243 DB.commit()
244 DB.close()
245
246#Main function
247def Main():
248 while( 1== 1) :
249 try:
250 print("Starting vote on " + VoteURL)
251 UserAgent = SelectUserAgent()
252 Proxy = SelectProxy().replace("\r", "")
253 CreateDriver(Proxy, UserAgent)
254 CurrentIP = GrabIPFromReferrer()
255 if (CheckIfIPUsedToday(CurrentIP) == False):
256 NavigateReferrer()
257 PKKey = GrabPKKey()
258 Solution = GetSolutionFromAntiCaptcha(Proxy, PKKey, UserAgent)
259 #Solution = GetSolutionFrom2Captcha(Proxy, PKKey, UserAgent)
260 EnterSolutionIntoField(Solution)
261 ClickVoteButton(CurrentIP)
262 driver.quit()
263 except Exception as Error:
264 print("Issue found. Error is: ")
265 print(Error)
266 driver.quit()
267Main()