Skip to content

Instantly share code, notes, and snippets.

Created November 4, 2019 10:45
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# dirbuster Asyncio example
# ©
# 11/2019
import asyncio
from aiohttp import ClientSession
import time
# global
lst = []
async def fetch(url, session, queue):
    while True:
        # Get a "work item" out of the queue.
        x = await queue.get()
        # Notify the queue that the "work item" has been processed.
        async with session.get(url+x.strip()) as response:
            if response.status == 200:
                print(url+x.strip() + "----" + str(response.status))
            x = await
with open("fuzz.txt", "r") as file:
    x = file.readlines()
url = ""
async def run(r):
    tasks = []
    start = time.time()
    queue = asyncio.Queue()
    for _ in range(len(x)):
        # await queue.put(x[_])
    async with ClientSession() as session:
 # how many tasks?
        for i in range(r):
            task = asyncio.create_task(fetch(url, session, queue))
 #join them
        await queue.join()
 #cancel remaining
        [task.cancel() for task in tasks]
        await asyncio.gather(*tasks, return_exceptions=True)
        # await asyncio.gather(*asyncio.all_tasks(), ).cancel()
        # you now have all response bodies in this variable
        # print(result)
        end = time.time()
        print(end - start)
if __name__ == '__main__': #change the number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment