import os
import platform

# Function to display the menu
def display_menu():
    print("1. Ping")
    print("2. Pathping")
    print("3. Traceroute")
    print("4. Whois")
    print("5. Netstat")
    print("6. NSLookup")
    print("7. Exit")

# Function to get user input
def get_input():
    while True:
        user_input = input("Enter your choice: ")
        if user_input.isdigit() and int(user_input) in [1, 2, 3, 4, 5, 6, 7]:
            return int(user_input)
        else:
            print("Invalid input, please enter a number from 1 to 7.")

# Function to ping the IP address
def ping_ip(ip):
    try:
        result = os.popen(f"ping {ip}").read()
        print(result)
    except Exception as e:
        print(f"Error: {e}")

# Function to pathping the IP address
def pathping_ip(ip):
    try:
        result = os.popen(f"pathping {ip}").read()
        print(result)
    except Exception as e:
        print(f"Error: {e}")

# Function to traceroute the IP address
def traceroute_ip(ip):
    try:
        if platform.system() == "Windows":
            result = os.popen(f"tracert {ip}").read()
        else:
            result = os.popen(f"traceroute {ip}").read()
        print(result)
    except Exception as e:
        print(f"Error: {e}")

# Function to whois the IP address
def whois_ip(ip):
    try:
        result = os.popen(f"whois {ip}").read()
        print(result)
    except Exception as e:
        print(f"Error: {e}")

# Function to display active network connections and listening ports
def netstat():
    try:
        if platform.system() == "Windows":
            result = os.popen("netstat -ano").read()
        else:
            result = os.popen("netstat -tuna").read()
        print(result)
    except Exception as e:
        print(f"Error: {e}")

# Function to perform DNS lookups
def nslookup():
    try:
        domain = input("Enter a domain name or IP address to look up: ")
        result = os.popen(f"nslookup {domain}").read()
        print(result)
    except Exception as e:
        print(f"Error: {e}")

# Main program
def main():
    ip = input("Enter an IP address: ")
    display_menu()
    while True:
        choice = get_input()
        if choice == 1:
            ping_ip(ip)
        elif choice == 2:
            pathping_ip(ip)
        elif choice == 3:
            traceroute_ip(ip)
        elif choice == 4:
            whois_ip(ip)
        elif choice == 5:
            netstat()
        elif choice == 6:
            nslookup()
        else:
            print("Goodbye!")
            break
        input("Press enter to continue...")
        display_menu()

if __name__ == "__main__":
    main()
