Advertisement
willysec_id

Domain to IP

Jul 4th, 2024
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.61 KB | Cybersecurity | 0 0
  1. import concurrent.futures
  2. import socket
  3. import os
  4. import shutil
  5. import threading
  6. from tqdm import tqdm
  7.  
  8. # Clear console based on OS
  9. if os.name == "nt":
  10.     os.system("cls")
  11. else:
  12.     os.system("clear")
  13.  
  14. class bcolors:
  15.     OKCYAN = '\033[96m'
  16.     OKGREEN = '\033[92m'
  17.     FAIL = '\033[91m'
  18.     ENDC = '\033[0m'
  19.     BOLD = '\033[1m'
  20.  
  21. print(bcolors.OKCYAN + """
  22. [#] Domain to IP
  23. [#] Coded by @willygoid
  24. [#] www.haxor.id
  25. """ + bcolors.ENDC)
  26.  
  27. sitelist = input("Sitelist : ")
  28. threadp = input("Thread (default: 100): ")
  29. if not threadp.isdigit():
  30.     threadp = 100
  31. else:
  32.     threadp = int(threadp)
  33.  
  34. # Ensure the output file is empty before starting and create a set to track unique IPs
  35. with open("ips.txt", "w") as f:
  36.     pass
  37.  
  38. unique_ips = set()
  39. lock = threading.Lock()
  40.  
  41. def save_to_txt(ip):
  42.     with open("ips.txt", "a") as f:
  43.         f.write(f"{ip}\n")
  44.  
  45. def resolveDns(host, pbar, width):
  46.     try:
  47.         checkHost = host.replace("https://", "").replace("http://", "").replace("www.", "")
  48.         ip = socket.gethostbyname(checkHost)
  49.         with lock:
  50.             if ip and ip not in unique_ips:
  51.                 unique_ips.add(ip)
  52.                 output = f"{bcolors.OKGREEN}{checkHost}{bcolors.ENDC} --> {ip}"
  53.                 print_wrapped(output, width)
  54.                 save_to_txt(ip)
  55.     except Exception as e:
  56.         output = f"{bcolors.FAIL}{checkHost}{bcolors.ENDC}:  Failed, domain inactive!"
  57.         print_wrapped(output, width)
  58.     finally:
  59.         pbar.update(1)
  60.  
  61. def print_wrapped(text, width):
  62.     if len(text) > width:
  63.         for i in range(0, len(text), width):
  64.             print(text[i:i+width])
  65.     else:
  66.         print(text)
  67.  
  68. def main():
  69.     with open(sitelist) as file:
  70.         hostnames = [line.strip() for line in file if line.strip()]
  71.  
  72.     total_hostnames = len(hostnames)
  73.     print(bcolors.BOLD + "===[ Start Work ]===" + bcolors.ENDC)
  74.  
  75.     # Get terminal size
  76.     terminal_size = shutil.get_terminal_size((80, 20))
  77.     width = terminal_size.columns
  78.  
  79.     # Create the progress bar
  80.     pbar = tqdm(total=total_hostnames, desc="Processing", position=1, leave=True, bar_format="{l_bar}{bar} | {n_fmt}/{total_fmt} [{elapsed}<{remaining}]", colour='cyan')
  81.  
  82.     with concurrent.futures.ThreadPoolExecutor(max_workers=threadp) as executor:
  83.         futures = [executor.submit(resolveDns, host, pbar, width) for host in hostnames]
  84.         for future in concurrent.futures.as_completed(futures):
  85.             future.result()
  86.  
  87.     pbar.close()
  88.     print(f'{bcolors.OKCYAN}Finished processing {total_hostnames} links{bcolors.ENDC}')
  89.  
  90. if __name__ == "__main__":
  91.     main()
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement