import socket def scan_ports(host, start_port, end_port): print(f"Scanning {host} from port {start_port} to {end_port}") for port in range(start_port, end_port + 1): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(1) # Set a timeout for the connection result = sock.connect_ex((host, port)) if result == 0: print(f"Port {port} is open") sock.close() if __name__ == "__main__": target_host = input("Enter the host to scan (e.g., 192.168.1.1): ") scan_ports(target_host, 1, 1024) # Scanning ports 1 to 1024