-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscrapaw.py
144 lines (125 loc) · 4.88 KB
/
scrapaw.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
"""
Copyright (C) 2021-2022, Loubaris
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You must obey the GNU General Public License. If you will modify
this file(s), you may extend this exception to your version
of the file(s), but you are not obligated to do so. If you do not
wish to do so, delete this exception statement from your version.
If you delete this exception statement from all source files in the
program, then also delete it here.
Contact:
Mail: [email protected]
"""
import os
import time
import sys
try:
import requests
except Exception as e:
print(f"Module requests is not installed\nError {e}")
logo = """
.▄▄ · ▄▄· ▄▄▄ ▄▄▄· ▄▄▄· ▄▄▄· ▄▄▌ ▐ ▄▌
▐█ ▀. ▐█ ▌▪▀▄ █·▐█ ▀█ ▐█ ▄█▐█ ▀█ ██· █▌▐█
▄▀▀▀█▄██ ▄▄▐▀▀▄ ▄█▀▀█ ██▀·▄█▀▀█ ██▪▐█▐▐▌
▐█▄▪▐█▐███▌▐█•█▌▐█ ▪▐▌▐█▪·•▐█ ▪▐▌▐█▌██▐█▌
▀▀▀▀ ·▀▀▀ .▀ ▀ ▀ ▀ .▀ ▀ ▀ ▀▀▀▀ ▀▪
made by Loubaris | github.com/Loubaris
"""
menu = """
Commands
- scrape <shodan> <sub+ject> <path_to_save> | Scrape IPs across the world
- exit | Exit program
API
- 'from scrapaw import scrape'
- 'scrape("shodan Example+Test+Android /Desktop/")'
(scrapaw)>"""
def scrape(command):
print("(scrapaw) - Launching scraping module..\n")
if command[1] == "shodan":
argv1 = command[2]
if argv1 == "":
print("Error, subject of search is empty. \nUsage: scrape <shodan> <sub+ject>")
else:
try:
print("- Connecting to shodan")
req = requests.get(f"https://www.shodan.io/search?query={argv1}", "html.parser")
curl_brut = open("curl_brut.txt", "w")
curl_brut.write(req.text)
curl_brut.close()
curl_brut = open("curl_brut.txt", "r")
curl_brut_content = curl_brut.read()
curl_brut.close()
os.remove("curl_brut.txt")
curl_result = open("curl_result.txt", "w")
print("- Filtering results")
for line in curl_brut_content.splitlines():
if "heading" in line:
if "h6" in line:
pass
else:
curl_result.write(f'{line}\n')
curl_result.close()
try:
for line in curl_brut_content.splitlines():
if "limit" in line:
print(f"Error while connecting to https://www.shodan.io/search?query={argv1}\n- Shodan daily usage limit excecced")
os.remove("curl_result.txt")
os.remove("shodan_list_ip.txt")
else:
try:
curl_result = open('curl_result.txt', "r")
content_curl = curl_result.readlines()
curl_result.close()
if command[3] == "":
ips = open(f"shodan_list_ip.txt", "w")
else:
ips = open(f"{command[3]}/shodan_list_ip.txt", "w")
for line in content_curl:
line = line.split("title", 1)[0]
result_ip = ''.join(i for i in line if i.isdigit() or i==".")
ips.write(f'{result_ip}\n')
ips.close()
except Exception as e:
print(f"Error while reading result \nError {e}")
print(f"- Results: {command[3]}shodan_list_ip.txt")
results = open(f'{command[3]}shodan_list_ip.txt', "r")
print(f"- {results.read()}")
results.close()
except Exception as e:
print(f"Error while reading https://www.shodan.io/search?query={argv1} result \nError {e}")
except Exception as e:
print(f"Error while connecting to https://www.shodan.io/search?query={argv1} \nError {e}")
else:
print("(scrapaw) - Usage: scrape <shodan> <sub+ject> <path_to_save>)")
def main():
os.system("cls")
print(logo)
command = input(menu)
command = command.split()
for i in range(5):
try:
command[i]
except Exception as e:
command.append("")
if command[0] == "scrape":
scrape(command)
else:
print("(scrapaw) - Unknown command")
if command[0] != "exit":
os.system("set /p DUMMY=Press Enter to continue")
else:
sys.exit()
os.system("cls")
while True:
try:
main()
except KeyboardInterrupt:
print(" Exiting..")
sys.exit()