-
Notifications
You must be signed in to change notification settings - Fork 0
/
password_routers.py
191 lines (153 loc) · 4.7 KB
/
password_routers.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
182
183
184
185
186
187
188
189
190
191
__author__ = 'AdriVillaB'
import time
import os
import requests
from BeautifulSoup import BeautifulSoup
import pickle
class Router(object):
def __init__(self, manufacturer=None, model=None, protocol=None, username=None, password=None):
"""
:param manufacturer:
:param model:
:param protocol:
:param username:
:param password:
:return:
"""
self.manufacturer = manufacturer
self.model = model
self.protocol = protocol
self.username = username
self.password = password
def insert_from_list(self, list):
"""
Insert data in the object from a list
:param list:
:return:
"""
self.manufacturer = "".join(list[0].contents)
self.model = "".join(list[1].contents)
self.protocol = "".join(list[2].contents)
self.username = "".join(list[3].contents)
self.password = "".join(list[4].contents)
def __str__(self):
"""
Export the object to a string
:return:
"""
return self.manufacturer+";"+self.model+";"+self.protocol+";"+self.username+";"+self.password+"\n"
def clear_screen():
"""
Clear the terminal
:return:
"""
if os.name == 'posix':
os.system('clear')
elif os.name == ('ce', 'nt', 'dos'):
os.system('cls')
def export_to_csv(data):
"""
Export a pickle file into CSV file
:return:
"""
with open("routers.csv", "wb") as f:
f.write("Manufacturer;Model;Protocol;Username;Password\n")
for router in data:
f.write(router.__str__())
def load_data(file):
"""
Load data inside a pickle file
:param file:
:return:
"""
data = []
try:
with open(file) as f:
data = pickle.load(f)
except:
data = []
return data
def save_data(data, file):
"""
Save data to a pickle file
:param data:
:param file:
:return:
"""
with open(file, 'wb') as f:
pickle.dump(data, f)
def delete_invalid_tags(html):
"""
Delete the tags unsupported by BeautifulSoap
:param html:
:return:
"""
invalid_tags = ['b', 'i', 'u']
for tag in invalid_tags:
for match in html.findAll(tag):
match.replaceWithChildren()
return html
def get_manufacturers():
"""
Retrieve the manufacturers of routerpasswords.com
:return manufacturers:
"""
r = requests.get("http://www.routerpasswords.com/")
html = BeautifulSoup(r.text)
html_models = html.findAll("option")
manufacturers = [model['value'] for model in html_models]
return manufacturers
def retrieve_all_info():
"""
Get all the info in routerpasswords.com page
:return retrieve_info:
"""
retrieve_info = []
manufacturers = get_manufacturers()
for index in xrange(0, len(manufacturers)):
post_data = {"findpass": 1, "router": manufacturers[index], "findpassword": "Find+Password"}
r = requests.post("http://www.routerpasswords.com/", data=post_data)
html = BeautifulSoup(r.text)
html = delete_invalid_tags(html)
html_info = html.table.findAll('td')
for index2 in xrange(0, len(html_info), 5):
router = Router()
router.insert_from_list(html_info[index2:index2+5])
retrieve_info.append(router)
print "[+]Extraidos los routers de la marca " + manufacturers[index]
time.sleep(1)
return retrieve_info
if __name__ == "__main__":
print "--------------------------------------------------"
print "------- RouterPasswords.com info extractor -------"
print "--------------------------------------------------"
while True:
try:
print "1) Extract the manufacturers: "
print "2) Extract all the info: "
print "3) Save info to pickle file"
print "4) Load info from pickle file"
print "5) Save to CSV file"
print "0) Exit"
print
option = int(input("What do you want to do? "))
info = []
if option == 1:
manufacturers = get_manufacturers()
print manufacturers
elif option == 2:
info = retrieve_all_info()
elif option == 3:
name_file = input("\nName of the file: ")
save_data(info, name_file)
elif option == 4:
name_file = input("\nName of the file: ")
info = load_data(name_file)
elif option == 5:
export_to_csv(info)
elif option == 0:
exit(0)
else:
exit(-1)
except:
pass