Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import asyncio
  4. from aiohttp import ClientSession
  5.  
  6. async def fetch(url):
  7.     try:
  8.         async with ClientSession() as session:
  9.             async with session.get(url) as response:
  10.                 return await url + '|' + checkwp(response.read())
  11.     except Exception:
  12.         return 'error'
  13.  
  14. async def bound_fetch(sem, url):
  15.     # getter function with semaphore
  16.     async with sem:
  17.         await fetch(url)
  18.  
  19. async def run(loop, l):
  20.     tasks = []
  21.     # create instance of Semaphore
  22.     sem = asyncio.Semaphore(1000)
  23.     for i in l:
  24.         # pass Semaphore to every GET request
  25.         task = asyncio.ensure_future(bound_fetch(sem, i))
  26.         tasks.append(task)
  27.  
  28.     responses = asyncio.gather(*tasks)
  29.     await responses
  30.  
  31.     wpfile = open('wp_xal.txt', 'a')
  32.     for item in responses:
  33.         f.write("%s\n" % item)
  34.     wpfile.close()
  35.  
  36. def checkwp(html):
  37.     if '/wp-admin/' in html or '/wp-content/' in html or '/wp-includes/' in html:
  38.         return True
  39.     else:
  40.         return False
  41.  
  42. def main():
  43.     l = []
  44.     f = open('xal', 'r')
  45.     l = f.read().splitlines()
  46.     f.close()
  47.  
  48.     count = len(l)
  49.    
  50.     print('%d domains loaded...' % count)
  51.  
  52.     loop = asyncio.get_event_loop()
  53.  
  54.     future = asyncio.ensure_future(run(loop, l))
  55.     loop.run_until_complete(future)
  56.  
  57. if __name__ == '__main__':
  58.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement