ajout port scanner

This commit is contained in:
2026-04-23 17:59:56 +02:00
parent 0522200855
commit 2d4f5a9f4d
4 changed files with 326 additions and 0 deletions

45
port_scanner/main.py Normal file
View File

@@ -0,0 +1,45 @@
import socket
import sys
import datetime
target = socket.gethostbyname(sys.argv[1])
today = datetime.datetime.now()
title = f"{target}_{today.year}_{today.month}_{today.day}_{today.hour}-{today.minute}.md"
print(f"Scanning target: {target}")
print(f"Output file: {title}\n")
with open(title, "a") as f:
for port in range(1, 65535):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
result = s.connect_ex((target, port))
if result == 0:
print(f"[+] Port {port} is open")
banner = ""
try:
# Only send HTTP request to common web ports
if port in [80, 8080, 8000]:
s.send(b"GET / HTTP/1.1\r\nHost: test\r\n\r\n")
banner = s.recv(1024).decode(errors="ignore").strip()
except:
banner = "No banner"
line = f"[+] {target}:{port}{banner}\n"
print(line)
f.write(line)
s.close()
except KeyboardInterrupt:
print("\nScan interrupted.")
sys.exit()
except Exception:
pass