Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # by : ./tokeichun
- import socket
- import urlparse
- import random
- from threading import *
- from threading import Thread
- from ConfigParser import ConfigParser
- from Queue import Queue
- # Color
- import colorama
- from colorama import init
- init(autoreset=True)
- bgreen = colorama.Fore.GREEN + colorama.Style.BRIGHT
- bred = colorama.Fore.RED + colorama.Style.BRIGHT
- bblue = colorama.Fore.BLUE + colorama.Style.BRIGHT
- byellow = colorama.Fore.YELLOW + colorama.Style.BRIGHT
- bmagneta = colorama.Fore.MAGENTA + colorama.Style.BRIGHT
- bcyan = colorama.Fore.CYAN + colorama.Style.BRIGHT
- bwhite = colorama.Fore.WHITE + colorama.Style.BRIGHT
- rancolor = [bgreen, byellow, bmagneta, bcyan]
- NORMALIZE = colorama.Style.RESET_ALL
- # Thread Class Worker
- pid_Restore = '.log_Session'
- class Worker(Thread):
- def __init__(self, tasks):
- Thread.__init__(self)
- self.tasks = tasks
- self.daemon = True
- self.start()
- def run(self):
- while True:
- func, args, kargs = self.tasks.get()
- try: func(*args, **kargs)
- except Exception, e: print 'a'
- self.tasks.task_done()
- class ThreadPool:
- def __init__(self, num_threads):
- self.tasks = Queue(num_threads)
- for _ in range(num_threads): Worker(self.tasks)
- def add_task(self, func, *args, **kargs):
- self.tasks.put((func, args, kargs))
- def wait_completion(self):
- self.tasks.join()
- # Class so Print won't messed up when using threading
- from threading import RLock
- class SynchronizedEcho(object):
- print_lock = RLock()
- def __init__(self, global_lock=True):
- if not global_lock:
- self.print_lock = RLock()
- def __call__(self, msg):
- with self.print_lock:
- print(msg)
- echo = SynchronizedEcho()
- def local_time():
- import time
- t = time.localtime()
- current_time = time.strftime("%H:%M:%S", t)
- return current_time
- def getHost(list):
- try:
- parseALL = urlparse.urlparse(list)
- hostName = urlparse.urlparse(list).hostname
- hostAddr = socket.gethostbyaddr(hostName)[0]
- urls = parseALL.scheme + '://' + hostAddr + parseALL.path
- return urls, hostName
- except Exception as e:
- # print(e)
- pass
- def runner(list):
- try:
- warna = random.choice(rancolor)
- hostAddress = getHost(list)[0]
- IP = getHost(list)[1]
- echo('[{}{}{}] Host Address : [{}{}{}] from IP : [{}{}{}]'.format(bwhite, local_time(), NORMALIZE, warna, hostAddress, NORMALIZE, warna, IP, NORMALIZE))
- open('log.Host Address.txt', 'a').write(hostAddress + '\n')
- except Exception as e:
- open('log.Fails Get Host.txt', 'a').write(list + '\n')
- pass
- # Threading Jobs Start Here!
- if __name__ == '__main__':
- try:
- configRead = ConfigParser()
- configRead.read(pid_Restore)
- targetList = configRead.get('DB', 'FILES')
- numThread = configRead.get('DB', 'THREAD')
- Session = configRead.get('DB', 'SESSION')
- print('Configuration Details : \n\t[+] List Files = %s\n\t[+] Thread = %s\n\t[+] Session = %s' % (targetList, numThread, Session))
- Quest = raw_input("\tLog Session Founds! Wanna Restore Session? [Y/n] : ")
- if "Y" in Quest or "y" in Quest:
- lists = open(targetList).read().split("\n"+Session)[1]
- readSplit = lists.splitlines()
- else:
- whatever31337 # Send Error to Exception
- except:
- try:
- targetList = sys.argv[1]
- numThread = sys.argv[2]
- readSplit = open(targetList).read().splitlines()
- except:
- try:
- targetList = raw_input("[+] Input List : ")
- readSplit = open(targetList).read().splitlines()
- except:
- print("File List not Founds!")
- exit()
- try:
- numThread = raw_input("[+] Input Threads : ")
- except:
- print("Thread value must be Numeric!")
- exit()
- pool = ThreadPool(int(numThread))
- for url in readSplit:
- urlSession = url
- if "://" in url:
- url = url
- else:
- url = "http://" + url
- if url.endswith('/'):
- url = url[:-1]
- try:
- pool.add_task(runner, url)
- except KeyboardInterrupt:
- session = open(pid_Restore, 'w')
- configSession = "[DB]\nFILES="+targetList+"\nTHREAD="+str(numThread)+"\nSESSION="+urlSession+"\n"
- session.write(configSession)
- session.close()
- print("\nJob Canceled! Session Saved on ( {} ) Files.".format(pid_Restore))
- exit()
- pool.wait_completion()
- try:
- import os
- os.remove(pid_Restore)
- except:
- pass
Add Comment
Please, Sign In to add comment