-
Notifications
You must be signed in to change notification settings - Fork 0
/
Run.py
117 lines (104 loc) · 4.23 KB
/
Run.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
from concurrent.futures import ThreadPoolExecutor, as_completed
import requests, os, json, re
from rich.console import Console
from rich import print
def Load_Domain_From_Files(file_path: str):
valid_domain = set()
domain_regex = re.compile(r"\b(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}\b")
try:
with open(f"{file_path}", "r") as reads:
for line in reads:
domains = domain_regex.findall(line)
valid_domain.update(domains)
return valid_domain
except FileNotFoundError:
print(
f"[bold white][[bold red]ERROR[bold white]][bold red] File '{file_path}' Tidak Ditemukan!"
)
return []
def Scanning_Domain(domain: str, valid_results: list):
try:
response = requests.get(
f"{domain}",
allow_redirects=False,
timeout=10,
verify=domain.startswith("https://"),
)
status_code = response.status_code
if status_code == 200:
print(f"[bold white][[bold green]200[bold white]][bold green] {domain}")
valid_results.append(f"{domain}")
else:
print(
f"[bold white][[bold yellow]{status_code}[bold white]][bold yellow] {domain}"
)
except requests.exceptions.ConnectionError:
print(
f"[bold white][[bold red]ERROR[bold white]][bold red] {domain} - Connection Error"
)
except requests.exceptions.Timeout:
print(f"[bold white][[bold red]ERROR[bold white]][bold red] {domain} - Timeout")
except requests.exceptions.RequestException as e:
print(f"[bold white][[bold red]ERROR[bold white]][bold red] {domain} - {e}")
def Save_Results(valid_results: list, output_file="Temporary/200.json"):
try:
with open(f"{output_file}", "w") as save:
json.dump(valid_results, save, indent=4)
print(
f"\n[bold white][[bold green]INFO[bold white]] Hasil Disimpan Ke[bold green] {output_file}[bold white]!"
)
except IOError as e:
print(
f"\n[bold white][[bold red]ERROR[bold white]][bold red] Gagal Menyimpan Hasil Ke {output_file} - {e}!"
)
def Main(file_path: str, protocol: str):
domains = Load_Domain_From_Files(file_path)
if not domains:
print(
"[bold white][[bold red]INFO[bold white]][bold red] Tidak Ada Domain Valid Untuk Diproses!"
)
return
else:
print(
f"[bold white][[bold green]INFO[bold white]] Jumlah Domain:[bold green] {len(domains)}\n"
)
valid_results = []
with ThreadPoolExecutor(max_workers=30) as executor:
futures = {
executor.submit(
Scanning_Domain, f"{protocol}://{domain}", valid_results
): domain
for domain in domains
}
for future in as_completed(futures):
domain = futures[future]
try:
future.result()
except Exception as e:
print(
f"[bold white][[bold red]ERROR[bold white]][bold red] Gagal Memeriksa {domain} - {e}"
)
Save_Results(valid_results=valid_results)
if __name__ == "__main__":
os.system("cls" if os.name == "nt" else "clear")
print(
r"""[bold red] _____ _____ _ _
[bold red]| __ \ / ____| | | |
[bold red]| | | | ___ _ __ ___ | | | |__ ___ ___| | _____ _ __
[bold red]| | | |/ _ \| '_ ` _ \| | | '_ \ / _ \/ __| |/ / _ \ '__|
[bold red]| |__| | (_) | | | | | | |____| | | | __/ (__| < __/ |
[bold white]|_____/ \___/|_| |_| |_|\_____|_| |_|\___|\___|_|\_\___|_|
"""
) # Coded by Rozhak
file_name = (
Console()
.input("[bold white][[bold green]MASUKAN[bold white]][bold white] Nama File: ")
.strip()
)
protocol = Console().input(
"[bold white][[bold green]MASUKAN[bold white]][bold white] Pakai (HTTPS/HTTP): "
)
if protocol.lower() == "http":
Main(file_path=file_name, protocol="http")
else:
Main(file_path=file_name, protocol="https")