Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions portscanner.py
Original file line number Diff line number Diff line change
@@ -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)