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

35
port_scanner/readme.md Normal file
View File

@@ -0,0 +1,35 @@
## Simple Port Scanner & Banner Grabber
### 🇬🇧 English
This project is a simple Python-based port scanner with basic banner grabbing capabilities. It scans a target host for open ports and attempts to retrieve service information from responsive ports.
The tool is designed as a learning project to explore networking concepts, socket programming, and basic reconnaissance techniques used in cybersecurity.
**Features:**
* Scan a range of TCP ports
* Detect open ports
* Perform basic banner grabbing
* Save results to a Markdown file
**Purpose:**
This tool is intended for educational use only. It helps understand how network services respond to connections and how information gathering works in real-world scenarios.
---
### 🇫🇷 Français
Ce projet est un scanner de ports simple en Python avec des fonctionnalités basiques de récupération de bannières (banner grabbing). Il permet de scanner une machine cible pour détecter les ports ouverts et dobtenir des informations sur les services actifs.
Cet outil est conçu comme un projet dapprentissage pour explorer les concepts de réseau, la programmation avec les sockets et les techniques de reconnaissance en cybersécurité.
**Fonctionnalités :**
* Scan dune plage de ports TCP
* Détection des ports ouverts
* Récupération basique des bannières
* Sauvegarde des résultats dans un fichier Markdown
**Objectif :**
Cet outil est uniquement destiné à un usage éducatif. Il permet de comprendre comment les services réseau répondent aux connexions et comment fonctionne la phase de collecte dinformations en conditions réelles.