DoS Attack Simulation using Python
Server code ….<scroll-down for the client code>
#!/usr/bin/python
#the threading function allows us to enable multi-threading so we can have simultaneous connecitons on the server
from socket import *
from threading import Thread
#open a list to read clients
clients = []
#funciton to manage client sockets
def clientHandler(c, addr):
global clients
print(addr, "is Connected")
#Loop to validate sockets, terminates at EoF.
try:
while True:
data = c.recv(1024)
if not data:
break
for client in clients:
if addr != client:
c.send(data, client)
except:
print("Error. Data not sent to all clients.")
#defines port server will listen to on host machine
HOST = '' #localhost
PORT = 8000
#creates port and listens to up to five a socket that used as an internet standard and specifically as IPV4.
#Socket is created an will listen to up to 5 clients simultaneously
s = socket(AF_INET, SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(5)
#notifies the user the server is running
print("Server is running on "+ str(PORT))
trds = []
for i in range(5):
c, addr = s.accept()
clients.append(addr)
t = Thread(target=clientHandler, args = (c, addr))
trds.append(t)
t.start()
for t in trds:
t.join()
#the threading function allows us to enable multi-threading so we can have simultaneous connecitons on the server
from socket import *
from threading import Thread
#open a list to read clients
clients = []
#funciton to manage client sockets
def clientHandler(c, addr):
global clients
print(addr, "is Connected")
#Loop to validate sockets, terminates at EoF.
try:
while True:
data = c.recv(1024)
if not data:
break
for client in clients:
if addr != client:
c.send(data, client)
except:
print("Error. Data not sent to all clients.")
#defines port server will listen to on host machine
HOST = '' #localhost
PORT = 8000
#creates port and listens to up to five a socket that used as an internet standard and specifically as IPV4.
#Socket is created an will listen to up to 5 clients simultaneously
s = socket(AF_INET, SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(5)
#notifies the user the server is running
print("Server is running on "+ str(PORT))
trds = []
for i in range(5):
c, addr = s.accept()
clients.append(addr)
t = Thread(target=clientHandler, args = (c, addr))
trds.append(t)
t.start()
for t in trds:
t.join()
Client
#!/usr/bin/python
from socket import *
s = socket()
s.connect(('', 8000))
s.send('I am client 1')
s.close()
from socket import *
s = socket()
s.connect(('', 8000))
s.send('I am client 2')
s.close()
from socket import *
s = socket()
s.connect(('', 8000))
s.send('I am client 3')
s.close()
from socket import *
s = socket()
s.connect(('', 8000))
s.send('I am client 4')
s.close()
from socket import *
s = socket()
s.connect(('', 8000))
s.send('I am client 5')
s.close()
from socket import *
s = socket()
s.connect(('', 8000))
s.send('I am client 1')
s.close()
from socket import *
s = socket()
s.connect(('', 8000))
s.send('I am client 2')
s.close()
from socket import *
s = socket()
s.connect(('', 8000))
s.send('I am client 3')
s.close()
from socket import *
s = socket()
s.connect(('', 8000))
s.send('I am client 4')
s.close()
from socket import *
s = socket()
s.connect(('', 8000))
s.send('I am client 5')
s.close()