johnmahugu

python web app mapper

Jun 3rd, 2015
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. import Queue
  2. import threading
  3. import os
  4. import urllib2
  5.  
  6. threads   = 10
  7.  
  8. target    = "http://www.test.com"
  9. directory = "/Users/justin/Downloads/joomla-3.1.1"
  10. filters   = [".jpg",".gif","png",".css"]
  11.  
  12. os.chdir(directory)
  13.  
  14. web_paths = Queue.Queue()
  15.  
  16. for r,d,f in os.walk("."):
  17.     for files in f:
  18.         remote_path = "%s/%s" % (r,files)
  19.         if remote_path.startswith("."):
  20.             remote_path = remote_path[1:]
  21.         if os.path.splitext(files)[1] not in filters:
  22.             web_paths.put(remote_path)
  23.  
  24. def test_remote():
  25.     while not web_paths.empty():
  26.         path = web_paths.get()
  27.         url = "%s%s" % (target, path)
  28.  
  29.         request = urllib2.Request(url)
  30.  
  31.         try:
  32.             response = urllib2.urlopen(request)
  33.             content  = response.read()
  34.  
  35.             print "[%d] => %s" % (response.code,path)
  36.  
  37.             response.close()
  38.        
  39.         except urllib2.HTTPError as error:
  40.             #print "Failed %s" % error.code
  41.             pass
  42.        
  43.        
  44.  
  45. for i in range(threads):
  46.     print "Spawning thread: %d" % i
  47.     t = threading.Thread(target=test_remote)
  48.     t.start()
Advertisement
Add Comment
Please, Sign In to add comment