-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebserverandAutofill.py
181 lines (137 loc) · 4.75 KB
/
WebserverandAutofill.py
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
from selenium import webdriver
import time
import datetime
from selenium.webdriver.chrome.options import Options
import win32gui
from subprocess import Popen
website = 'https://www.toro.com/en/customer-support/product-registration'
windows = []
myFil = 'chromedriver'
myFil2 = 'torro'
myFil3 = 'ConsoleWindowClass'
biglist = []
import socket
import sys
HOST = ''
PORT = 7000
line = ''
# Create socket on port
def reFresh():
global line
print('# Socket created')
line = ''
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.bind((HOST, PORT))
except socket.error as msg:
print('# Bind failed. ')
time.sleep(5)
reFresh()
print('# Socket bind complete')
# Start listening on socket
s.listen(10)
print('# Socket now listening')
# Wait for client
conn, addr = s.accept()
print('# Connected to ' + addr[0] + ':' + str(addr[1]))
# Receive data from client
data = conn.recv(1024)
line = data.decode('UTF-8')
# convert to string (Python 3 only)
line = line.split('\n') # remove newline character
line = line.pop()
line = line.replace('+', ' ')
line = line.replace('%40', '@')
line = line.split('%2C')
p = line.pop()
firstname, lastname, address1, address2, city, state, postalcode, country, phonenumber, email, commercialuse, ModelNumber, serialnumber, dateofpurchase, productupdatesandoffers = line
print(line)
# add error checking on each variable to make sure the right stuff is submitted
# get rid of spaces or whatever and convert @ symbol back
# add persistence via a for loop that waits 5 seconds before restarting
s.close()
time.sleep(1)
if (line != ''):
getLoginInfo()
time.sleep(5)
reFresh()
def findWindows():
win32gui.EnumWindows(_enumW, windows)
time.sleep(0.5)
lookharder()
# lookharder2() BE AFRAID VERY AFRAID
def Hwin(zz):
win32gui.ShowWindow(zz, 0)
def Swin(zz):
win32gui.ShowWindow(zz, 3)
def MelnickMash(hwnd):
win32gui.DestroyWindow(hwnd)
def _enumW(hwnd, windows):
className = win32gui.GetClassName(hwnd)
text = win32gui.GetWindowText(hwnd)
windows.append([hwnd, className, text])
def lookharder():
j = -1
for x in windows:
j = j + 1
if myFil in windows[j][2]:
Hwin(windows[j][0])
if myFil2 in windows[j][2] and myFil3 == windows[j][1]:
Hwin(windows[j][0])
def getLoginInfo():
global line
firstname, lastname, address1, address2, city, postalcode, country, state, phonenumber, email, commercialuse, ModelNumber, serialnumber, dateofpurchase, productupdatesandoffers = line
#lastname = lastname.translate({ord(c): None for c in ' '})
#state = state.translate({ord(c): None for c in ' '})
#postalcode = postalcode.translate({ord(c): None for c in ' '})
postalcode = int(postalcode)
phonenumber = int(phonenumber)
#if('%40' in email):
# a = email
# b = "%40"
# for char in b:
# a = a.replace(char, " ")
# email = a
browser = webdriver.Chrome()
browser.get(website)
time.sleep(2)
elem1 = browser.find_element_by_name('firstname')
elem2 = browser.find_element_by_name('lastname')
elem3 = browser.find_element_by_name('address1')
elem4 = browser.find_element_by_name('address2')
elem5 = browser.find_element_by_name('city')
elem6 = browser.find_element_by_name('postalcode')
elem7 = browser.find_element_by_name('country')
elem8 = browser.find_element_by_name('state')
elem9 = browser.find_element_by_name('phonenumber')
elem10 = browser.find_element_by_name('email')
elem11 = browser.find_element_by_name('commercialuse')
elem12 = browser.find_element_by_name('ModelNumber')
elem13 = browser.find_element_by_name('serialnumber')
elem14 = browser.find_element_by_name('dateofpurchase')
elem15 = browser.find_element_by_id('productupdatesandoffers')
elem16 = browser.find_element_by_id('submitForm')
elem1.send_keys(firstname)
elem2.send_keys(lastname)
elem3.send_keys(address1)
elem4.send_keys(address2) # address 2
elem5.send_keys(city)
elem6.send_keys(postalcode)
elem7.send_keys(country)
elem8.send_keys(state)
elem9.send_keys(phonenumber)
elem10.send_keys(email)
elem11.send_keys(commercialuse)
elem12.send_keys(ModelNumber)
elem13.send_keys(serialnumber)
elem14.send_keys(dateofpurchase)
elem12.click()
elem15.click()
elem12.click()
time.sleep(5)
browser.quit()
#raise SystemExit
def main():
reFresh()
print('this happened')
main()