Untitled

 avatar
unknown
plain_text
19 days ago
851 B
3
Indexable
import socket

def scan_port(ip, port):
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(0.5)

        result = sock.connect_ex((ip, port))
        if result == 0:
            print(f"Port {port} is open on {ip}")
        sock.close()
    except Exception as e:
        print(f"Error scanning port {port}: {e}")

def scan_ports(ip, start_port, end_port):
    print(f"Scanning {ip} for open ports from {start_port} to {end_port}...")
    for port in range(start_port, end_port + 1):
        scan_port(ip, port)

def main():
    target_ip = input("Enter the target IP address: ")
    start_port = int(input("Enter the starting port: "))
    end_port = int(input("Enter the ending port: "))

    scan_ports(target_ip, start_port, end_port)

if __name__ == "__main__":
    main()
Editor is loading...
Leave a Comment