31 lines
943 B
Python
31 lines
943 B
Python
import nmap
|
|
import json
|
|
|
|
# Initialisation du scanner
|
|
scanner = nmap.PortScanner()
|
|
|
|
# Définir la plage IP à scanner (celle de VirtualBox Host-only adapter : 192.168.56.0/24)
|
|
network_range = "192.168.56.0/24"
|
|
|
|
print(f"Scanning network: {network_range} ...")
|
|
|
|
# Scan du réseau avec détection d'hôte actif (-sn) et scan des ports TCP les plus courants (-T4)
|
|
scanner.scan(hosts=network_range, arguments="-T4 -F")
|
|
|
|
# Stockage des résultats
|
|
results = {}
|
|
|
|
for host in scanner.all_hosts():
|
|
if scanner[host].state() == "up":
|
|
print(f"Host up: {host}")
|
|
results[host] = {
|
|
"hostname": scanner[host].hostname(),
|
|
"state": scanner[host].state(),
|
|
"tcp": scanner[host].get("tcp", {})
|
|
}
|
|
|
|
# Enregistrement des résultats en JSON
|
|
with open("network_scan_report.json", "w") as f:
|
|
json.dump(results, f, indent=4)
|
|
|
|
print("\nScan terminé. Rapport sauvegardé dans 'network_scan_report.json'.")
|