-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcategory_search.py
80 lines (60 loc) · 2.25 KB
/
category_search.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
import os
import requests
import re
from colorama import init, Fore
init()
def check_domain_in_blocklist(source_path, target_domain):
try:
with open(source_path, "r") as file:
lines = [
line.strip()
for line in file
if line.strip() and not line.startswith(("#", "!"))
]
results = []
pattern = rf"(?:^|\s|\.){re.escape(target_domain)}$"
for line in lines:
match = re.search(pattern, line, flags=re.MULTILINE)
if match:
results.append(True)
return results
except FileNotFoundError:
print(f"Error: File '{source_path}' not found.")
return []
def find_blocking_blocklists(target_domain, category_sources):
blocking_category_blocklists = []
for name, source_path in category_sources.items():
if check_domain_in_blocklist(source_path, target_domain):
blocking_category_blocklists.append(name)
if blocking_category_blocklists:
print(
Fore.CYAN + f"Domain '{target_domain}' found in the following categories:\n"
)
for blocklist in blocking_category_blocklists:
print(Fore.CYAN + f" - {blocklist}\n")
if not blocking_category_blocklists:
print(Fore.RED + f"Domain '{target_domain}' not found in any categories.")
print(Fore.RESET, end="")
if __name__ == "__main__":
category_blocklist_sources = {
"Suspicious": "domlists/firebogsus.txt",
"Advertising": "domlists/firebogad.txt",
"Tracking": "domlists/firebogtrack.txt",
"Malicious": "domlists/firebogmal.txt",
"Other": "domlists/firebogother.txt",
}
while True:
target_domain = input("Enter a domain to find (or type 'exit' to close): ")
if target_domain.lower() == "exit":
print("Exiting the script.")
break
if (
"." not in target_domain
or target_domain.startswith(".")
or target_domain.endswith(".")
or ".." in target_domain
):
print(Fore.YELLOW + "Invalid domain")
print(Fore.RESET, end="")
continue
find_blocking_blocklists(target_domain, category_blocklist_sources)