Created
January 31, 2024 08:45
-
-
Save akoserwal/4260a58f1a8f053fa2c4018d897d0a91 to your computer and use it in GitHub Desktop.
simple-port-scanner.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
def scan_ports(target, start_port, end_port): | |
open_ports = [] | |
for port in range(start_port, end_port + 1): | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.settimeout(1) | |
result = sock.connect_ex((target, port)) | |
if result == 0: | |
open_ports.append(port) | |
sock.close() | |
return open_ports | |
if __name__ == "__main__": | |
target_ip = "127.0.0.1" # Replace with the target IP address | |
start_port = 1 | |
end_port = 1024 | |
open_ports = scan_ports(target_ip, start_port, end_port) | |
if open_ports: | |
print(f"Open ports on {target_ip}: {open_ports}") | |
else: | |
print(f"No open ports found on {target_ip}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment