Created
November 8, 2019 23:12
-
-
Save 0xdade/fd01467e45939a8ceaf7700da5e7c3c0 to your computer and use it in GitHub Desktop.
Simple script for downloading a list of ip addresses that match a query from a natlas server
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
#!/usr/bin/env python3 | |
''' | |
Simple script for downloading a list of ip addresses that match a query from a natlas server | |
Input: | |
- Required: natlas url | |
- Required: Search query, contained in quotes if it includes spaces | |
- Optional: filename to save results to | |
Example: ./fetch-natlas-results.py https://natlas.io 'ports.port:443 "application/json"' json-443.txt | |
If no filename is present, the script will spit the results to stdout once they are all downloaded | |
''' | |
import requests | |
import sys | |
from requests.packages.urllib3.exceptions import InsecureRequestWarning | |
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) | |
targets = [] | |
page = 1 | |
natlasaddr = sys.argv[1] | |
query = sys.argv[2] | |
while True: | |
url = f"{natlasaddr}/search?q={query}&p={page}&f=hostlist" | |
response = requests.get(url, verify=False) | |
if response.content: | |
targets += response.content.decode('ascii').split('\n') | |
else: | |
break | |
page += 1 | |
unique_targets = list(set(targets)) | |
if len(sys.argv) > 3: | |
with open(sys.argv[3], 'w') as outfile: | |
outfile.write('\n'.join(unique_targets)) | |
else: | |
print("\n".join(unique_targets)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment