-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatus.py
245 lines (205 loc) · 8.93 KB
/
status.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
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
import cmd
import requests
from termcolor import colored
from tqdm import tqdm
import subprocess
import socket
import argcomplete
import argparse
import os
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
import time
import sys
import csv
from termcolor import colored
def animate_banner(text):
colors = ['red', 'yellow', 'green', 'cyan', 'blue', 'magenta']
delay = 0.001
for i in range(len(banner)):
char = banner[i]
color = colors[i % len(colors)]
colored_char = colored(char, color, attrs=['bold'])
print(colored_char, end='', flush=True)
time.sleep(delay)
print()
banner = """
██████╗ ███████╗ ███████╗██╗███╗ ██╗██████╗ ███████╗██████╗
██╔══██╗██╔════╝ ██╔════╝██║████╗ ██║██╔══██╗██╔════╝██╔══██╗
██║ ██║███████╗█████╗█████╗ ██║██╔██╗ ██║██║ ██║█████╗ ██████╔╝
██║ ██║╚════██║╚════╝██╔══╝ ██║██║╚██╗██║██║ ██║██╔══╝ ██╔══██╗
██████╔╝███████║ ██║ ██║██║ ╚████║██████╔╝███████╗██║ ██║
╚═════╝ ╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚═════╝ ╚══════╝╚═╝ ╚═╝
--------------c̶o̶d̶e̶d̶ b̶y̶ w̶h̶i̶t̶e̶d̶e̶v̶i̶l̶----------------------------------
"""
animate_banner(banner)
class MyCmd(cmd.Cmd):
prompt = colored(">>>>", "blue")
def __init__(self):
super().__init__()
self.ip = []
self.status = []
self.domain = []
self.errors = []
self.default_filename = "output.csv"
def do_quit(self, arg):
return True
def help_find_status(self):
print("Detailed help for find_status command:")
print("Usage: find_status")
print("Description: This command finds the status codes for each IP address.")
print("")
def help_print_status(self):
print("Detailed help for print_status command:")
print("Usage: print_status")
print("Description: This command prints the list of IP addresses and their corresponding status codes.")
print("")
def help_save_status(self):
print("Detailed help for save_status command:")
print("Usage: save_status [filename]")
print("Description: This command saves the IP addresses and their corresponding status codes into a CSV file.")
print("If [filename] is not provided, a default file name will be used.")
print("")
def help_quit(self):
print("Detailed help for quit command:")
print("Usage: quit")
print("Description: This command exits the program.")
print("")
def help_cls(self):
print("Detailed help for cls command:")
print("Usage: cls")
print("Description: This command clears the IP, status, and domain lists.")
print("")
def help_print(self):
print("Detailed help for print command:")
print("Usage: print")
print("Description: This command prints the list of IP addresses and their corresponding status codes.")
print("")
def help_print_ip(self):
print("Detailed help for print_ip command:")
print("Usage: print_ip")
print("Description: This command prints the list of IP addresses.")
print("")
def help_read(self):
print("Detailed help for read command:")
print("Usage: read <filename>")
print("Description: This command reads IP addresses from the specified file and adds them to the IP list.")
print("")
def do_save_status(self, arg):
filename = arg.strip()
if not filename:
filename = self.default_filename
try:
with open(filename, "w", newline="") as file:
writer = csv.writer(file)
writer.writerow(["IP", "Status Code"])
for ip, status in zip(self.ip, self.status):
writer.writerow([ip, status])
print(colored(f"[+] Status codes saved to '{filename}'","green"))
except IOError as e:
print(colored(f"Error saving status codes: {str(e)}","red"))
def check_port(self, ip, port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(2)
result = sock.connect_ex((ip, port))
sock.close()
return result == False
def find_status_code(self, ip, timeout=2):
if self.check_port(ip, 443):
url = "https://" + ip + ":443"
elif self.check_port(ip, 80):
url = "http://" + ip + ":80"
else:
return "No Web Interface"
try:
command = ["curl", "-Is","-k","-w", "%{http_code}", "-o", "/dev/null", url]
result = subprocess.run(command, capture_output=True, text=True, timeout=timeout)
output = result.stdout.strip()
if output.isdigit():
status_code = int(output)
return status_code
else:
return 000
except subprocess.TimeoutExpired:
return "Time out"
except subprocess.CalledProcessError:
return "000"
except ValueError:
return "000"
def do_find_status(self, arg):
try:
with tqdm(total=len(self.ip), desc=colored("Finding Status Codes", "yellow"),
unit=colored("IP", "cyan"), ncols=80, bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt}") as pbar:
for i in self.ip:
status = self.find_status_code(i)
self.status.append(status)
pbar.update(1)
except Exception as e:
self.errors.append(str(e))
def do_print_status(self, args):
try:
print(colored("[+] FOUND STATUS CODES", "yellow"))
print("-" * 50)
print(",".join(map(str, self.status)))
except IndexError:
print(colored("[!] Error: No Status codes found yet :(", "red"))
def do_print(self, args):
try:
print(colored("[+] STATUS CODE AND IP LIST", "yellow"))
print("-" * 50)
for ip, status in zip(self.ip, self.status):
print(colored(ip, "cyan") + " : " + colored(str(status), "magenta"))
except IndexError:
print(colored("[!] Error: No IP and Status codes found yet :(", "red"))
def do_print_ip(self, arg):
try:
print(colored("[+] IPs FOUND", "yellow"))
print("-" * 50)
print(",".join(self.ip))
except IndexError:
print(colored("[!] Error: No IPs found yet :(", "red"))
def do_read(self, line):
filename = line.strip()
try:
with open(filename, "r") as f:
print(colored(f"[+] Reading file: {filename}", "green"))
lines = [line.rstrip('\n') for line in f]
self.ip.extend(lines)
except FileNotFoundError:
self.errors.append("File not found!")
def complete_read(self, text, line, begidx, endidx):
current_dir = os.getcwd()
files = [f for f in os.listdir(current_dir) if os.path.isfile(os.path.join(current_dir, f))]
return [f for f in files if f.startswith(text)]
def do_cls(self, arg):
self.ip = []
self.status = []
self.domain = []
self.errors = []
print(colored("[+] Cleared IP, status, domain, and errors", "yellow"))
def default(self, line):
try:
subprocess.run(line, shell=True, check=True)
except FileNotFoundError:
print(colored(f"Command not found: {line}", "red"))
except KeyboardInterrupt:
print(colored("\n[!] Execution interrupted by user", "red"))
except Exception as e:
self.errors.append(str(e))
def postcmd(self, stop, line):
if self.errors:
print(colored("[!] Exception Errors:", "red"))
print("-" * 50)
for error in self.errors:
print(colored(error, "red"))
self.errors = []
return stop
if __name__ == "__main__":
try:
parser = argparse.ArgumentParser()
argcomplete.autocomplete(parser)
MyCmd().cmdloop()
except KeyboardInterrupt:
print(colored("[!] User Interrupt", "red"))
except Exception as e:
print(colored(f"[!] Error: {str(e)}", "red"))