-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatvision.py
More file actions
69 lines (63 loc) · 4.66 KB
/
Copy pathcatvision.py
File metadata and controls
69 lines (63 loc) · 4.66 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
#!/usr/bin/python3
import sys #importing sys module for error handling and commandline arguments
import socket #socket module for connecting ports
from datetime import datetime #datetime module for showing the time when the program starts running
import threading #threading for running the code effectively
from concurrent.futures import ThreadPoolExecutor
def scan_port(target, port): #defined a function which checks if a port is open for the target
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # ipv4 and tcp port
s.settimeout(1) #how long to connect until the socket connection breaks
result = s.connect_ex((target, port)) #connect_ex returns 0 if a port is open
if result ==0:
print(f"Port {port} is open") #if port is open then shows this message
s.close() #if a port is open then close that connection after scanning
except socket.error as e: #error handling if there is a socket error occurrence
print(f"socket error {e} on port {port}") #if so show this message
except Exception as e: #anyother exceptions..
print(f"Unexpected error occurred {e} on port {port}") #-then show this message
def main(): # the main function, this is the function which is going to run the first
arg = len(sys.argv) #assign the length of the commandline arguments
target = sys.argv[arg-1] #and then take the last part of the argument and assign it as the target
try:
target_ip = socket.gethostbyname(target) #use the method to get the ip in case of a domain name
except socket.gaierror: #error handling
print(f"Unable to resolve host to the address{target}") #if the entered domain is not valid then show this
sys.exit(1) #exit the program with the error code 1
print("\033[91mC A T V I S I O N 👀\033[0m")
print("""\033[91m
⢠
⠀⠀⢸⣧
⠀⠀⠀⣿⣷⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡔
⠀⠀⠀⠭⣿⣿⣿⣶⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣴⣾⡿⠁
⠀⠀⠀⠘⡿⣿⡿⣿⣿⣿⣿⣦⣴⣶⣶⣶⣶⣦⣤⣤⣀⣀⠀⠀⠀⠀⠀⢀⣀⣤⣲⣿⣿⣿⠟⠀⠀
⠀⠀⠀⠀⠐⡝⢿⣌⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣤⣾⣿⣿⣿⣿⣿⡿⠃⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠲⡝⡷⣮⣝⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣛⣿⣿⠿⠃⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢀⣴⣿⣦⣝⠓⠭⣿⡿⢿⣿⣿⣛⠻⣿⠿⠿⣿⣿⣿⣿⣿⣿⡿⣇⣇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣴⣿⣿⣿⣿⣿⣿⣤⡀⠈⠉⠚⠺⣿⠯⢽⣿⣷⣄⣶⣷⢾⣿⣯⣾⣿⠿⠃⠀⠀⠀⠀⠀⠀
⠀⢠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⡟⠀⠀⣴⣿⣿⣼⠈⠉⠃⠋⢹⠁⢀⡇⠀⠀⠀⠀⠀⠀
⢠⢿⣿⡟⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⣀⣀⣀⣀⣴⣿⣿⡿⣿⠀⠀⠀⠀⠇⠀⣼⡇⠀⠀⠀⠀⠀⠀
⠈⠑⢿⢿⣾⣿⣿⡿⠿⠿⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠿⢿⡄⢦⣤⣤⣶⣿⣿⣷⡀⠀⠀⠀⠀⠀
⠀⠀⠀⠙⠘⠛⠋⠁⠁⣀⢉⡉⢻⡻⣯⣻⣿⢻⣿⣀⠀⠀⠀⢠⣾⣿⣿⣿⣹⠉⣍⢁⠀⠀⠀⠀⠀
⠀⠀⣀⠠⠔⠒⠋⠀⡈⠀⠠⠤⠀⠓⠯⣟⣻⣻⠿⠛⠁⠀⠀⠣⢽⣿⡻⠿⠋⠰⠤⣀⡈⠒⢄⠀⠀
⠀⠀⠀⠀⡀⠔⠊⠁⠀⣀⠔⠈⠁⠀⠀⠀⠀⠀⣶⠂⠀⠀⠀⢰⠆⠀⠀⠀⠈⠒⢦⡀⠉⠢⠀⠁⠀
⠀⠀⠀⠊⠀⠀⠀⠀⠎⠁⠀⠀⠀⠀⠀⠀⠀⠀⠋⠀⠀⠀⠰⠃⠀⠀⠀⠀⠀⠀⠀⠈⠂⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠿⠭⠯⠭⠽⠿\033[0m""")
print("-" * 50) #banner design when the code starts to run
print(f"Scanning target {target_ip}") #this will show the message as scanning the target
print(f"Time started: {datetime.now()}") #this will show the date of scanning the target
print("-" * 50)
try:
# Limit the number of concurrent threads to a safe value (e.g. 100)
with ThreadPoolExecutor(max_workers=100) as executor:
for port in range(1, 65536):
executor.submit(scan_port, target_ip, port)
except KeyboardInterrupt: #error handling in case of a keyboard interruption, then exit the program
print("/nExiting program")
sys.exit(0) #no error code
except socket.error as e: #socket error
print(f"Socket error occurred : {e}") #socket error handling
if __name__ == "__main__": #only run the program from here
main() #finally calling the main function to start the process