From 04b147b42089efa6b0925db019eaf42e39d3b3d5 Mon Sep 17 00:00:00 2001 From: saiazwin006 Date: Fri, 10 Oct 2025 12:43:27 +0530 Subject: [PATCH] Add files via upload --- portscanner.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 portscanner.py diff --git a/portscanner.py b/portscanner.py new file mode 100644 index 0000000..22caed4 --- /dev/null +++ b/portscanner.py @@ -0,0 +1,24 @@ +import socket + +def port_scan(target_host, target_ports): + for port in target_ports: + try: + # Create a TCP socket + client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + client.settimeout(1) # Set timeout for this socket + + # Try to connect to the target host and port + client.connect((target_host, port)) + print(f"✅ Port {port} is open") + + except (socket.timeout, socket.error): + print(f"❌ Port {port} is closed or unreachable") + + finally: + client.close() + +# Example usage +target_host = "example.com" # Replace with IP or domain +target_ports = [22, 80, 443, 8000] # Common ports + +port_scan(target_host, target_ports) \ No newline at end of file