-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrealityScanner.py
More file actions
276 lines (235 loc) · 9.44 KB
/
realityScanner.py
File metadata and controls
276 lines (235 loc) · 9.44 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
import os
import re
import ssl
import sys
import webbrowser
import requests
import urllib.request
import socket
from bs4 import BeautifulSoup
from fake_useragent import UserAgent
import tldextract
from tkinter import ttk
from tkinter import messagebox
from threading import Thread
import customtkinter
class ScannerApp:
URL_MAIN = "https://bgp.tools"
URL_ROUTE = "/prefix"
URL = URL_MAIN + URL_ROUTE
TIMEOUT = 3
def __init__(self):
customtkinter.set_appearance_mode("system")
customtkinter.set_default_color_theme("blue")
self.root = customtkinter.CTk()
self.root.title("Reality Friendly Scanner | Coded by: @B3H1")
self.root.minsize(500, 500)
self.icon_path = self.resource_path("icon.ico")
self.root.iconbitmap(self.icon_path)
self.create_table()
self.create_input_fields()
self.create_progress_bar()
def resource_path(self, relative_path):
base_path = getattr(
sys,
'_MEIPASS',
os.path.dirname(os.path.abspath(__file__))
)
return os.path.join(base_path, relative_path)
def create_table(self):
self.table = ttk.Treeview(
self.root, columns=('URL', 'IP', 'Info'), show='headings', height=15
)
self.table.bind('<Double-1>', self.copy_cell_content)
self.table.heading('URL', text='URL')
self.table.heading('IP', text='IP')
self.table.heading('Info', text='Info')
self.table.column('URL', width=200)
self.table.column('IP', width=200)
self.table.column('Info', width=300)
self.table.pack(pady=10)
def create_input_fields(self):
self.ip_label = customtkinter.CTkLabel(
self.root, text="Your server IP address", fg_color="transparent"
)
self.ip_label.pack(pady=5)
self.ip_entry = customtkinter.CTkEntry(self.root, placeholder_text="IP:")
self.ip_entry.pack(pady=5)
self.search_button = customtkinter.CTkButton(
master=self.root, text="Search", command=self.search_input
)
self.search_button.pack(pady=10)
def create_progress_bar(self):
self.percentage_label = customtkinter.CTkLabel(
self.root, text="0%", fg_color="transparent"
)
self.percentage_label.pack(side='right', anchor='w', padx="10")
self.progress_bar = customtkinter.CTkProgressBar(
self.root, orientation="horizontal", width=100
)
self.progress_bar.set(0)
self.progress_bar.pack(side='right', anchor='w', pady="10")
self.link = customtkinter.CTkLabel(
self.root, text="About", font=('Helvetica', 15), cursor="hand2",
padx="10"
)
self.link.pack(side='left')
self.link.bind("<Button-1>", lambda e: self.callback("https://behnam.cloud"))
def copy_cell_content(self, event):
item = self.table.selection()[0]
column_id = self.table.identify_column(event.x)
cell_content = self.table.item(item)['values'][0]
self.root.clipboard_clear()
self.root.clipboard_append(cell_content)
messagebox.showinfo("Domain Copied", f"{cell_content} copied to clipboard.")
def add_row(self, url, ip, info):
self.table.insert('', 'end', values=(url, ip, info))
def log_label_set(self, text):
self.ip_label.configure(text=f"{text}")
def callback(self, url):
webbrowser.open_new_tab(url)
def search_input(self):
ip_search = self.ip_entry.get()
thread = Thread(target=self.run, args=(ip_search,))
thread.start()
def send_request(self, ip):
ua = UserAgent()
header = {'User-Agent': ua.random}
try:
res_try = requests.get(self.URL_MAIN, headers=header, timeout=5)
if res_try.status_code == 403:
self.log_label_set("Your IP BLOCKED by bgp.tools")
return False
except requests.exceptions.RequestException as e:
self.log_label_set("Cannot connect to bgp.tools \n Check your internet connection")
return False
try:
res = requests.get(
f"{self.URL}/{ip}", headers=header, timeout=self.TIMEOUT
)
except requests.exceptions.RequestException as e:
self.log_label_set("Cannot connect to bgp.tools \n Please try again")
return False
return res
def cipher_checker(self, domain):
context = ssl.create_default_context()
try:
with socket.create_connection((domain, 443)) as sock:
with context.wrap_socket(sock, server_hostname=domain) as ssock:
ssock_version = ssock.version()
ssock_cipher = ssock.cipher()
return ssock_cipher
except socket.error:
pass
def domain_ip_range_checker(self, domain):
ip = socket.gethostbyname(domain)
if ip:
return ip
def domain_checker(self, domain):
domain = domain.replace(" ", "")
domain_s = f"https://{domain}"
try:
status = urllib.request.urlopen(domain_s, timeout=self.TIMEOUT).getcode()
if status == 200:
ssock_cipher = self.cipher_checker(domain)
ssock_version = ssock_cipher[1]
if ssock_version == "TLSv1.3":
dns = self.domain_ip_range_checker(domain)
return domain, ssock_cipher, dns
else:
return False
except urllib.error.URLError:
return False
def check_useless_domain(self, url):
regex_ip_in_domain = r'(?:[0-9]{1,3}\-){2}[0-9]{1,3}|(?:[0-9]{1,3}\.){2}[0-9]{1,3}'
regex_subdomain = r'[.-]'
if not re.findall(regex_ip_in_domain, url):
ext = tldextract.extract(url)
if not re.search(regex_subdomain, ext[0]):
if not ext[0] == 'mail':
return True
return False
def fdns_html_parser(self, html):
domains = []
if not html:
return False
soup = BeautifulSoup(html.text, 'html.parser')
table = soup.find('table', id='fdnstable')
if table:
all_tr = table.findAll('tr')
all_tr.pop(0)
for tr in all_tr:
_domain = tr.find('td', {'class': 'smallonmobile nowrap'})
if _domain.text:
_domain = _domain.text
if _domain.find(",") != -1:
_domain = _domain.split(",")
for domain in _domain:
domain = domain.replace(" ", "")
if domain.find('(') != -1:
domain = domain.split("(")[0]
domain = domain.replace(" ", "").strip()
domains.append(domain)
else:
domains.append(_domain)
return domains
def rdns_html_parser(self, html):
domains = []
if not html:
return False
soup = BeautifulSoup(html.text, 'html.parser')
table = soup.find('table', id='rdnstable')
if table:
all_tr = table.findAll('tr')
all_tr.pop(0)
for tr in all_tr:
_domain = tr.find('td', {'class': 'smallonmobile nowrap'})
if _domain.text[-1] == ".":
_domain = _domain.text[:-1]
else:
_domain = _domain.text
domains.append(_domain)
return domains
def run_dns(self, domains):
if domains:
all_count = len(domains)
count = 0
for domain in domains:
self.log_label_set(domain)
if self.check_useless_domain(domain):
st = self.domain_checker(domain)
if st:
domain, ssock_cipher, dns = st
self.add_row(domain, dns, ssock_cipher)
count += 1
prog = round((count / all_count) * 100)
self.percentage_label.configure(text=f"{prog}%")
self.progress_bar.set(prog / 100)
self.root.update()
else:
self.log_label_set("There is no domain")
self.progress_bar.stop()
def validate_ipv4_address(self, address):
ipv4_pattern = (
r"^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\."
r"(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
)
return re.match(ipv4_pattern, address)
def run(self, input_ip):
if self.validate_ipv4_address(input_ip):
self.log_label_set("Waiting for getting data from bgp.tools ...")
html_response = self.send_request(input_ip)
if html_response:
rdns = self.rdns_html_parser(html_response)
fdns = self.fdns_html_parser(html_response)
self.log_label_set("Checking Reversed Dns Domains ...")
self.run_dns(rdns)
self.log_label_set("Checking Forward Dns Domains ...")
self.run_dns(fdns)
self.log_label_set("Done!")
else:
self.log_label_set("Please Enter a Valid IPv4 address")
self.progress_bar.stop()
if __name__ == "__main__":
app = ScannerApp()
app.root.mainloop()