diff --git a/README.md b/README.md index f7b96ec4..eb760638 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,7 @@ More information on contributing and the general code of conduct for discussion | 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. | 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. | | Selfie with Python | [Selfie with Python](https://github.com/DhanushNehru/Python-Scripts/tree/master/Selfie%20with%20Python) | Take your selfie with python . | +| 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. | | 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! | | Snake Water Gun | [Snake Water Gun](https://github.com/DhanushNehru/Python-Scripts/tree/master/Snake%20Water%20Gun) | A game similar to Rock Paper Scissors. | | Sorting | [Sorting](https://github.com/DhanushNehru/Python-Scripts/tree/master/Sorting) | Algorithm for bubble sorting. | diff --git a/Simple DDOS/README.md b/Simple DDOS/README.md new file mode 100644 index 00000000..9d9d2904 --- /dev/null +++ b/Simple DDOS/README.md @@ -0,0 +1,69 @@ +# Multithreaded HTTP Requests with Python + +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. + +## Features +- Sends concurrent HTTP requests to a specified URL. +- Supports multiple request methods (GET, POST, etc.). +- Allows customizing headers, cookies, data, and URL parameters. +- The number of threads and the duration of the requests can be controlled. +- Uses ThreadPoolExecutor to handle multithreading efficiently. + +## Requirements +- Python 3.x +- `requests` library + +To install the `requests` library, run: +```bash +pip install requests +``` + +## Usage + +### Function: `make_request` +This function sends a single HTTP request to a given URL with the specified parameters. +- **Arguments**: + - `url` (str): The URL to send the request to. + - `method` (str): The HTTP method to use (default: GET). + - `headers` (dict): Optional HTTP headers to include. + - `cookies` (dict): Optional cookies to include. + - `data` (dict): Optional data for POST requests. + - `params` (dict): Optional URL parameters. + +- **Example**: +make_request("https://example.com", method='POST', data={"key": "value"}) + +### Function: `start_requests` +This function sends multiple HTTP requests concurrently for a specified duration. +- **Arguments**: + - `url` (str): The URL to send the requests to. + - `method` (str): The HTTP method to use (default: GET). + - `headers` (dict): Optional HTTP headers to include. + - `cookies` (dict): Optional cookies to include. + - `data` (dict): Optional data for POST requests. + - `params` (dict): Optional URL parameters. + - `num_threads` (int): The number of threads to use (default: 5). + - `duration` (int): The duration in seconds to send requests (default: 10 seconds). + +- **Example**: +url = "https://example.com/api" +start_requests(url, method='GET', num_threads=5, duration=15) + +## How It Works +1. The `start_requests` function uses `ThreadPoolExecutor` to manage the specified number of threads. +2. Each thread sends an HTTP request to the given URL. +3. The process continues until the specified duration ends. +4. The `make_request` function handles sending the requests and printing the response status codes. + +## Example Usage +url = "https://example.com/api" +start_requests(url, num_threads=5, duration=15) # Sends requests for 15 seconds using 5 threads. + +## Customization +- You can modify the method, headers, cookies, data, or params in the function calls to fit your use case. +- For POST requests, pass data through the `data` argument. + +start_requests("https://example.com/post", method='POST', data={'key': 'value'}, num_threads=10, duration=20) + +## License +This project is licensed under the MIT License. diff --git a/Simple DDOS/ddos.py b/Simple DDOS/ddos.py new file mode 100644 index 00000000..9abf8f64 --- /dev/null +++ b/Simple DDOS/ddos.py @@ -0,0 +1,27 @@ +import requests +from concurrent.futures import ThreadPoolExecutor +import time + +def make_request(url, method='GET', headers=None, cookies=None, data=None, params=None): + try: + + response = requests.request(method, url, headers=headers, cookies=cookies, data=data, params=params) + print(f"Response code: {response.status_code}") + except requests.exceptions.RequestException as e: + print(f"Error occurred: {e}") + +def start_requests(url, method='GET', headers=None, cookies=None, data=None, params=None, num_threads=5, duration=10): + executor = ThreadPoolExecutor(max_workers=num_threads) + end_time = time.time() + duration # Time to stop the requests + + while time.time() < end_time: + for _ in range(num_threads): + executor.submit(make_request, url, method, headers, cookies, data, params) + + executor.shutdown(wait=True) + print("Requests completed.") + +# Usage example +url = "Sample URL" +start_requests(url, num_threads=5, duration=15) #time in seconds +#change methods as required \ No newline at end of file