Templates
Script Template
#!/usr/bin/env python3
# >>>>>>>>> packages
import socket
from termcolor import colored
import argparse
import sys
#>>>>>> global variables
#>>>> ctrl+C break
def def_handler(sig,frame):
print(f"saliendo del programa")
sys.exit(1)
signal.signal(signal.SIGINT,def_handler)
# >>>>>> get arguments
import argparse
import sys
def get_arguments():
parser = argparse.ArgumentParser(description='Fast TCP port scanner')
parser.add_argument("-t", "--target", dest="target", required=True, help="Victim target to scan (e.g., -t 10.10.10.10)")
options = parser.parse_args()
if not options.target:
parser.print_help()
sys.exit(1)
return options.target
target_ip = get_arguments()
print("Target IP:", target_ip)
#>>>>>>>>>>>>>>>>>>>Class
#>>>>>>>> Functions
def port_scanner(host,port,s):
try:
s.connect((host,port))
print(colored(f"el puerto {port} esta abierto" , 'green'))
s.close()
except (socket.timeout, ConnectionRefusedError):
print(colored(f"el puerto {port} esta cerrado", 'red'))
s.close()
#>>>>>>>>>> Principal
def main():
IP = get_arguments()
for port in range(1000):
s = create_socket()
port_scanner(IP,port,s)
# >>>>>>>> start programa
if __name__ == '__main__':
main()