├── README.md └── vt-subdomains.py /README.md: -------------------------------------------------------------------------------- 1 | This is a simple python script to collect sub domains from the Virus Total API. 2 | 3 | First setup an environment variable `VTAPIKEY` with your [Virus Total](https://www.virustotal.com) API key. 4 | 5 | ```shell 6 | unset HISTFILE #to avoid logging your key to ~/.bash_history 7 | export VTAPIKEY= 8 | ``` 9 | Then do a search: 10 | 11 | Example: `python3 vt-subdomains.py apple.com` 12 | -------------------------------------------------------------------------------- /vt-subdomains.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import requests 3 | from os import environ 4 | import os 5 | import sys 6 | import json 7 | 8 | def main(domain, apikey): 9 | url = 'https://www.virustotal.com/vtapi/v2/domain/report' 10 | params = {'apikey':apikey,'domain':domain} 11 | try: 12 | response = requests.get(url, params=params) 13 | jdata = response.json() 14 | domains = sorted(jdata['subdomains']) 15 | except(KeyError): 16 | print("No domains found for %s" % domain) 17 | exit(0) 18 | except(requests.ConnectionError): 19 | print("Could not connect to www.virtustotal.com", file=sys.stderr) 20 | exit(1) 21 | 22 | for domain in domains: 23 | print(domain) 24 | 25 | if __name__ == '__main__': 26 | if len(sys.argv) != 2: 27 | print("Usage: python3 vt-subdomains.py domain.com", file=sys.stderr) 28 | sys.exit(1) 29 | domain = sys.argv[1] 30 | if environ.get('VTAPIKEY'): 31 | apikey = os.environ['VTAPIKEY'] 32 | else: 33 | print("VTAPIKEY environment variable not set. Quitting.", file=sys.stderr) 34 | sys.exit(1) 35 | main(domain, apikey) 36 | --------------------------------------------------------------------------------