Advertisement
betrayed

ip_generator.py

Apr 29th, 2024
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. import os, random
  2. from colorama import Fore
  3. os.system('clear')
  4.  
  5. print(Fore.RED + '''
  6.  ___ ___      _ _     ___                       _          
  7. |_ _| _ \__ _| | |   / __|___ _ _  ___ _ _ __ _| |_ ___ _ _
  8.  | ||  _/\ V /_  _| | (_ / -_) ' \/ -_) '_/ _` |  _/ _ \ '_|
  9. |___|_|   \_/  |_|   \___\___|_||_\___|_| \__,_|\__\___/_|  
  10.                                                            
  11. ''')
  12. try:
  13.     num = int(input(Fore.WHITE + ' Number of IP address/s to generate: '))
  14.     txt = input(' Name of output file (ex hosts.txt): ')
  15. except KeyboardInterrupt:
  16.     sys.exit(Fore.YELLOW + ' \r\nAborted by user.\r\n')
  17. except:
  18.     sys.exit(Fore.RED + ' \r\nInput error detected!\r\n')
  19.    
  20. print('\r\n')
  21.  
  22. try:
  23.     with open(txt, 'w') as file:
  24.         for _ in range(num):
  25.             _ip = ".".join(str(random.randint(0, 255)) for _ in range(4))
  26.             print(Fore.WHITE + ' Writing IP ' + Fore.GREEN + _ip + Fore.WHITE + ' to file.')
  27.             file.write(_ip + '\n')
  28. except KeyboardInterrupt:
  29.     sys.exit(Fore.YELLOW + ' \r\nAborted by user.\r\n')
  30.  
  31. print(Fore.WHITE + '\r\n Done!')
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement