# Import the socket library for network connections
import socket
# Import the PrettyTable library for generating tables to make the output more readable
from prettytable import PrettyTable
# Define a dictionary containing common ports and their potential security vulnerabilities
vulnerabilities = {
    80: "HTTP (Hypertext Transfer Protocol) - for unencrypted web traffic",
    443: "HTTPS (Secure HTTP) - for encrypted web traffic",
    22: "SSH (Secure Shell) - for secure remote access",
    21: "FTP (File Transfer Protocol) - for file transfers",
    25: "SMTP (Simple Mail Transfer Protocol) - for email transmission",
    23: "Telnet - for remote terminal access",
    53: "DNS (Domain Name System) - for domain name resolution",
    110: "POP3 (Post Office Protocol version 3) - for email retrieval",
    143: "IMAP (Internet Message Access Protocol) - for email retrieval",
    3306: "MySQL - for MySQL database access",
    3389: "RDP (Remote Desktop Protocol) - for remote desktop connections on Windows",
    8080: "HTTP alternate port - commonly used as a secondary port for HTTP",
    8000: "HTTP alternate port - commonly used as a secondary port for HTTP",
    8443: "HTTPS alternate port - commonly used as a secondary port for HTTPS",
    5900: "VNC (Virtual Network Computing) - for remote desktop access",
    # More ports and their security vulnerabilities can be added as needed
}
# Define a function to display open ports and their potential security issues
def display_table(open_ports):
    table = PrettyTable(["Open Port", "Potential Security Issues"])
    for port in open_ports:
        vulnerability = vulnerabilities.get(port, "This port has no known vulnerabilities associated with common services")
        table.add_row([port, vulnerability])
    print(table)
# Define a function to scan common ports on the target host
def scan_top_ports(target):
    open_ports = []  # List to store open ports
    top_ports = [21, 22, 23, 25, 53, 80, 110, 143, 443, 3306, 3389, 5900, 8000, 8080, 8443]  # Define 15 common ports
    for port in top_ports:
        try:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.settimeout(1)  # Set connection timeout
            result = sock.connect_ex((target, port))
            if result == 0:
                open_ports.append(port)
            sock.close()
        except KeyboardInterrupt:
            sys.exit()
        except socket.error:
            pass
    return open_ports
# Main function
def main():
    target = input("Please enter the URL or IP address of the website to scan: ")
    open_ports = scan_top_ports(target)
    if not open_ports:
        print("The target host has no open ports.")
    else:
        print("Open ports and their related potential security issues:")
        display_table(open_ports)
# If this script is run directly
if __name__ == "__main__":
    main()