MiTro | tool ai:
import asyncio
import time
import aiohttp
from aiolimiter import AsyncLimiter
from colorama import
tool ai:
import asyncio
import time
import aiohttp
from aiolimiter import AsyncLimiter
from colorama import Fore, init
def create_proxy_file_if_not_exists():
if not os.path.exists(\"proxy.txt\"):
with open(\"proxy.txt\", \"w\") as proxy_file:
print(f\"{Fore.YELLOW}\\nĐã phát hiện chưa có file proxy.txt và tiến hành tạo thành công !{Style.RESET_ALL}\")
sys.exit()
elif os.path.exists(\"proxy.txt\") and os.path.getsize(\"proxy.txt\") == 0:
print(f\"{Fore.RED}\\nLỗi: Vui lòng thêm proxy vào file proxy.txt để sử dụng ddos tool!{Style.RESET_ALL}\")
sys.exit()
else:
with open(\"proxy.txt\", \"r\") as proxy_file:
for line in proxy_file:
proxy = line.strip()
if not re.match(r\"^\\d+\\.\\d+\\.\\d+\\.\\d+:\\d+$\", proxy):
print(f\"{Fore.RED}\\nLỗi: Proxy phải là http/https, vui lòng nhập đúng định dạng ip proxy ví dụ: 103.167.22.58:80{Style.RESET_ALL}\")
init(autoreset=True)
async def load_test():
url = input(\"[?] Nhập URL website của bạn: \").strip()
rps = int(input(\"[?] Giới hạn request/giây (RPS): \"))
duration = int(input(\"[?] Thời gian test (giây): \"))
ramp = int(input(\"[?] Ramp-up (giây): \"))
limiter = AsyncLimiter(rps, time_period=1)
total = success = fail = 0
latencies = []
start_time = time.time()
async with aiohttp.ClientSession() as session:
async def worker():
nonlocal total, success, fail
async with limiter:
t0 = time.time()
try:
async with session.get(url, timeout=5) as r:
await r.text()
latency = (time.time() - t0) * 1000
latencies.append(latency)
success += 1
print(Fore.GREEN + f\"[OK] {r.status} | {latency:.1f} ms\")
except Exception as e:
fail += 1
print(Fore.RED + f\"[FAIL] {str(e)}\")
total += 1
while time.time() - start_time < duration:
elapsed = time.time() - start_time
# ramp-up
if elapsed < ramp:
current_rps = int(rps * (elapsed / ramp))
limiter._rate = max(1, current_rps)
tasks = [asyncio.create_task(worker()) for _ in range(limiter._rate)]
await asyncio.gather(*tasks)
if latencies:
p95 = sorted(latencies)[int(len(latencies) * 0.95)]
else:
p95 = 0
print(Fore.YELLOW + \"\\n========== KẾT QUẢ ==========\")
print(Fore.CYAN + f\"Total requests : {total}\")
print(Fore.GREEN + f\"Success : {success}\")
print(Fore.RED + f\"Fail : {fail}\")
print(Fore.CYAN + f\"P95 latency : {p95:.1f} ms\")
print(Fore.YELLOW + \"==============================\\n\")
if __name__ == \"__main__\":
try:
asyncio.run(load_test())
except KeyboardInterrupt:
print(\"\\n[!] Đã dừng load test\")
nho ae sua ho