import socket
import multiprocessing
from multiprocessing import Pool
from functools import partial
import sys
import time
import subprocess
REDE = "10.0.112"
HOSTS = range(1, 255)
PORTAS = [21, 22, 80, 443, 445]
TIMEOUT = 0.3
PROCESSOS = 50
def testa_porta(ip, porta):
"""Retorna True se a porta estiver aberta."""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(TIMEOUT)
s.connect((ip, porta))
s.close()
return True
except:
return False
def scan_host(ip):
"""Escaneia portas de um único host."""
portas_abertas = []
for porta in PORTAS:
if testa_porta(ip, porta):
portas_abertas.append(porta)
if portas_abertas:
return (ip, portas_abertas)
return None
def barra_progresso(atual, total):
"""Renderiza barra de progresso no terminal."""
largura = 40
progresso = int(largura * (atual / total))
barra = "=" * progresso + "." * (largura - progresso)
print(f"\r[{barra}] {atual}/{total} hosts", end="")
sys.stdout.flush()
if __name__ == "__main__":
print(f"=== PORT SCANNER — Rede {REDE}.0/24 ===\n")
ips = [f"{REDE}.{i}" for i in HOSTS]
resultados = []
pool = Pool(PROCESSOS)
total = len(ips)
atual = 0
for resultado in pool.imap_unordered(scan_host, ips):
atual += 1
barra_progresso(atual, total)
if resultado:
resultados.append(resultado)
pool.close()
pool.join()
print("\n\n=== HOSTS ATIVOS E PORTAS ABERTAS ===")
for ip, portas in resultados:
print(f"[+] {ip} -> portas abertas: {portas}")
print("\n=== ARP ===")
try:
saida = subprocess.check_output(["arp", "-a"], text=True)
print(saida)
except:
print("Comando arp não disponível.")