ToKeiChun

IPs List to Domain List

Oct 19th, 2021 (edited)
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.28 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # by : ./tokeichun
  3. import socket
  4. import urlparse
  5. import random
  6. from threading import *
  7. from threading import Thread
  8. from ConfigParser import ConfigParser
  9. from Queue import Queue
  10.  
  11. # Color
  12. import colorama
  13. from colorama import init
  14. init(autoreset=True)
  15.  
  16. bgreen = colorama.Fore.GREEN + colorama.Style.BRIGHT
  17. bred = colorama.Fore.RED + colorama.Style.BRIGHT
  18. bblue = colorama.Fore.BLUE + colorama.Style.BRIGHT
  19. byellow = colorama.Fore.YELLOW + colorama.Style.BRIGHT
  20. bmagneta = colorama.Fore.MAGENTA + colorama.Style.BRIGHT
  21. bcyan = colorama.Fore.CYAN + colorama.Style.BRIGHT
  22. bwhite = colorama.Fore.WHITE + colorama.Style.BRIGHT
  23.  
  24. rancolor = [bgreen, byellow, bmagneta, bcyan]
  25. NORMALIZE = colorama.Style.RESET_ALL
  26.  
  27. # Thread Class Worker
  28. pid_Restore = '.log_Session'
  29.  
  30. class Worker(Thread):
  31.     def __init__(self, tasks):
  32.         Thread.__init__(self)
  33.         self.tasks = tasks
  34.         self.daemon = True
  35.         self.start()
  36.  
  37.     def run(self):
  38.         while True:
  39.             func, args, kargs = self.tasks.get()
  40.             try: func(*args, **kargs)
  41.             except Exception, e: print 'a'
  42.             self.tasks.task_done()
  43.  
  44. class ThreadPool:
  45.     def __init__(self, num_threads):
  46.         self.tasks = Queue(num_threads)
  47.         for _ in range(num_threads): Worker(self.tasks)
  48.  
  49.     def add_task(self, func, *args, **kargs):
  50.         self.tasks.put((func, args, kargs))
  51.  
  52.     def wait_completion(self):
  53.         self.tasks.join()
  54.        
  55. # Class so Print won't messed up when using threading
  56. from threading import RLock
  57.  
  58. class SynchronizedEcho(object):
  59.     print_lock = RLock()
  60.     def __init__(self, global_lock=True):
  61.         if not global_lock:
  62.             self.print_lock = RLock()
  63.  
  64.     def __call__(self, msg):
  65.         with self.print_lock:
  66.             print(msg)
  67.  
  68. echo = SynchronizedEcho()  
  69.  
  70. def local_time():
  71.     import time
  72.    
  73.     t = time.localtime()
  74.     current_time = time.strftime("%H:%M:%S", t)
  75.     return current_time
  76.  
  77. def getHost(list):
  78.     try:
  79.         parseALL = urlparse.urlparse(list)
  80.  
  81.         hostName = urlparse.urlparse(list).hostname
  82.         hostAddr = socket.gethostbyaddr(hostName)[0]
  83.        
  84.         urls = parseALL.scheme + '://' + hostAddr + parseALL.path
  85.         return urls, hostName
  86.        
  87.     except Exception as e:
  88.         # print(e)
  89.         pass
  90.        
  91. def runner(list):
  92.     try:
  93.         warna = random.choice(rancolor)
  94.        
  95.         hostAddress = getHost(list)[0]
  96.         IP = getHost(list)[1]
  97.         echo('[{}{}{}] Host Address : [{}{}{}] from IP : [{}{}{}]'.format(bwhite, local_time(), NORMALIZE, warna, hostAddress, NORMALIZE, warna, IP, NORMALIZE))
  98.         open('log.Host Address.txt', 'a').write(hostAddress + '\n')
  99.        
  100.     except Exception as e:
  101.         open('log.Fails Get Host.txt', 'a').write(list + '\n')
  102.         pass
  103.    
  104. # Threading Jobs Start Here!
  105. if __name__ == '__main__':
  106.     try:
  107.         configRead = ConfigParser()
  108.         configRead.read(pid_Restore)
  109.         targetList = configRead.get('DB', 'FILES')
  110.         numThread = configRead.get('DB', 'THREAD')
  111.         Session = configRead.get('DB', 'SESSION')
  112.        
  113.         print('Configuration Details : \n\t[+] List Files = %s\n\t[+] Thread = %s\n\t[+] Session = %s' % (targetList, numThread, Session))
  114.         Quest = raw_input("\tLog Session Founds! Wanna Restore Session? [Y/n] : ")
  115.        
  116.         if "Y" in Quest or "y" in Quest:
  117.             lists = open(targetList).read().split("\n"+Session)[1]
  118.             readSplit = lists.splitlines()
  119.         else:
  120.             whatever31337 # Send Error to Exception
  121.     except:
  122.         try:
  123.             targetList = sys.argv[1]
  124.             numThread = sys.argv[2]
  125.             readSplit = open(targetList).read().splitlines()
  126.         except:
  127.             try:
  128.                 targetList = raw_input("[+] Input List : ")
  129.                 readSplit = open(targetList).read().splitlines()
  130.             except:
  131.                 print("File List not Founds!")
  132.                 exit()
  133.             try:
  134.                 numThread = raw_input("[+] Input Threads : ")
  135.             except:
  136.                 print("Thread value must be Numeric!")
  137.                 exit()
  138.                
  139.     pool = ThreadPool(int(numThread))
  140.  
  141.     for url in readSplit:
  142.         urlSession = url
  143.        
  144.         if "://" in url:
  145.             url = url
  146.         else:
  147.             url = "http://" + url
  148.            
  149.         if url.endswith('/'):
  150.             url = url[:-1]
  151.                    
  152.         try:
  153.             pool.add_task(runner, url)
  154.         except KeyboardInterrupt:
  155.             session = open(pid_Restore, 'w')
  156.             configSession = "[DB]\nFILES="+targetList+"\nTHREAD="+str(numThread)+"\nSESSION="+urlSession+"\n"
  157.             session.write(configSession)
  158.             session.close()
  159.             print("\nJob Canceled! Session Saved on ( {} ) Files.".format(pid_Restore))
  160.             exit()
  161.            
  162.     pool.wait_completion()
  163.     try:
  164.         import os
  165.         os.remove(pid_Restore)
  166.     except:
  167.         pass
  168.  
Add Comment
Please, Sign In to add comment