Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pydig
- import argparse
- import os
- from sys import argv
- parser = argparse.ArgumentParser(description='''
- Make sure, that you installed:
- python 3
- pip install pydig
- file path to the domains list should looks like:
- example.com
- ei.example.com
- ''')
- parser.add_argument('-f','--file', required=True, help='file path to the domains list')
- parser.add_argument('-n','--name', required=True , help='output name file')
- def get_subdomain_IP(domain):
- return pydig.query(domain, 'A')
- def add_subdomain_IP(pathToFile, output_name):
- ip_list_result = ''
- with open(pathToFile, 'r+') as f:
- domain_list = f.readlines()
- existing_domains = []
- for domain in domain_list:
- domain = domain.replace('\n','')
- ip_list = get_subdomain_IP(domain)
- for ip in ip_list:
- if ip in existing_domains:
- continue
- else:
- existing_domains.append(ip)
- ip_list_result += f'{ip}\n'
- f.close()
- path_to_output = os.path.join(os.path.dirname(entryArgs.file), f'{output_name}-ip-list.txt')
- with open(path_to_output, 'w+') as f:
- f.write(ip_list_result)
- f.close
- if __name__ == "__main__":
- entryArgs = parser.parse_args(argv[1:])
- if entryArgs.file == None:
- raise Exception('The file path not been passed. Please, use --file param')
- else:
- add_subdomain_IP(entryArgs.file, entryArgs.name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement