Created
August 15, 2017 11:57
-
-
Save xsxsd/1facb24c657c60e96f3b5226b92ac06d to your computer and use it in GitHub Desktop.
waybackrobots.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import re | |
| import sys | |
| from multiprocessing.dummy import Pool | |
| def robots(host): | |
| r = requests.get( | |
| 'https://web.archive.org/cdx/search/cdx\ | |
| ?url=%s/robots.txt&output=json&fl=timestamp,original&filter=statuscode:200&collapse=digest' % host) | |
| results = r.json() | |
| results.pop(0) # The first item is ['timestamp', 'original'] | |
| return results | |
| def getpaths(snapshot): | |
| url = 'https://web.archive.org/web/{0}/{1}'.format(snapshot[0], snapshot[1]) | |
| robotstext = requests.get(url).text | |
| if 'Disallow:' in robotstext: # verify it's acually a robots.txt file, not 404 page | |
| paths = re.findall('/.*', robotstext) | |
| return paths | |
| return [] | |
| if __name__ == '__main__': | |
| if len(sys.argv) < 2: | |
| print('Usage:\n\tpython3 waybackrobots.py <url>') | |
| sys.exit() | |
| host = sys.argv[1] | |
| snapshots = robots(host) | |
| print('Found %s unique results' % len(snapshots)) | |
| print('This is gonna take some time...') | |
| pool = Pool(4) | |
| paths = pool.map(getpaths, snapshots) | |
| unique_paths = set() | |
| for i in paths: | |
| unique_paths.update(i) | |
| filename = '%s-robots.txt' % host | |
| with open(filename, 'w') as f: | |
| f.write('\n'.join(unique_paths)) | |
| print('[*] Saved results to %s' % filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment