-
Notifications
You must be signed in to change notification settings - Fork 1
/
mapper.py
73 lines (64 loc) · 1.7 KB
/
mapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import contextlib
import os
import queue
import requests
import sys
import threading
import time
FILTERS = [".jpg", ".gif", ".png", ".css"]
TARGET = "http://boodelyboo.com/wordpress"
THREADS = 10
answers = queue.Queue()
web_paths = queue.Queue()
def gather_paths():
for root, _, files in os.walk('.'):
for fname in files:
if os.path.splitext(fname)[1] in FILTERS:
continue
path = os.path.join(root, fname)
if path.startswith('.'):
path = path[1:]
print(path)
web_paths.put(path)
@contextlib.contextmanager
def chdir(path):
"""
On enter, change directory to specified path.
On exit, change direcgory to original.
"""
this_dir = os.getcwd()
os.chdir(path)
try:
yield
finally:
os.chdir(this_dir)
def test_remote():
while not web_paths.empty():
path = web_paths.get()
url = f'{TARGET}{path}'
time.sleep(2)
r = requests.get(url)
if r.status_code == 200:
answers.put(url)
sys.stdout.write('+')
else:
sys.stdout.write('x')
sys.stdout.flush()
def run():
mythreads = list()
for i in range(THREADS):
print(f'Spawning thread {i}')
t = threading.Thread(target=test_remote)
mythreads.append(t)
t.start()
for thread in mythreads:
thread.join()
if __name__ == '__main__':
with chdir("/home/tim/Downloads/wordpress"):
gather_paths()
input('Press return to continue.')
run()
with open('myanswers.txt', 'w') as f:
while not answers.empty():
f.write(f'{answers.get()}\n')
print('done')