Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import pydig
  2. import argparse
  3. import os
  4. from sys import argv
  5.  
  6. parser = argparse.ArgumentParser(description='''
  7. Make sure, that you installed:
  8. python 3
  9. pip install pydig
  10. file path to the domains list should looks like:
  11. example.com
  12. ei.example.com
  13. ''')
  14. parser.add_argument('-f','--file', required=True, help='file path to the domains list')
  15. parser.add_argument('-n','--name', required=True , help='output name file')
  16.  
  17. def get_subdomain_IP(domain):
  18. return pydig.query(domain, 'A')
  19.  
  20. def add_subdomain_IP(pathToFile, output_name):
  21. ip_list_result = ''
  22.  
  23. with open(pathToFile, 'r+') as f:
  24. domain_list = f.readlines()
  25. existing_domains = []
  26. for domain in domain_list:
  27. domain = domain.replace('\n','')
  28. ip_list = get_subdomain_IP(domain)
  29. for ip in ip_list:
  30. if ip in existing_domains:
  31. continue
  32. else:
  33. existing_domains.append(ip)
  34. ip_list_result += f'{ip}\n'
  35. f.close()
  36.  
  37. path_to_output = os.path.join(os.path.dirname(entryArgs.file), f'{output_name}-ip-list.txt')
  38. with open(path_to_output, 'w+') as f:
  39. f.write(ip_list_result)
  40. f.close
  41.  
  42.  
  43. if __name__ == "__main__":
  44. entryArgs = parser.parse_args(argv[1:])
  45. if entryArgs.file == None:
  46. raise Exception('The file path not been passed. Please, use --file param')
  47. else:
  48. add_subdomain_IP(entryArgs.file, entryArgs.name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement