Take this simple port scanner, and make it better.
#!/usr/bin/env python3
import socket
import sys
host = sys.argv[1] if len(sys.argv) > 1 else input("Host: ")
print(f"Scanning {host}...\n")
for port in range(1, 1025):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.2)
if s.connect_ex((host, port)) == 0:
try:
service = socket.getservbyport(port)
except:
service = "unknown"
print(f"{port:5d}/tcp OPEN ({service})")
s.close()
print("\nDone.")
Note: If you build a longer version, paste your code into a pastebin or similar code-sharing page and leave the link in your reply. That keeps the thread readable while still letting everyone review the code.
--
Darth Yoda
"Debugging the galaxy, one bite at a time."
Darth Yoda
"Debugging the galaxy, one bite at a time."