forked from rahulkadavil/pentest-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolve.py
executable file
·140 lines (105 loc) · 3.04 KB
/
resolve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/python3
# I don't believe in license.
# You can do whatever you want with this program.
import os
import sys
import socket
import argparse
from colored import fg, bg, attr
from threading import Thread
from queue import Queue
from multiprocessing.dummy import Pool
def banner():
print("""
_
_ __ ___ ___ ___ | |_ _____ _ __ _ _
| '__/ _ \/ __|/ _ \| \ \ / / _ \ | '_ \| | | |
| | | __/\__ \ (_) | |\ V / __/ _ | |_) | |_| |
|_| \___||___/\___/|_| \_/ \___| (_) | .__/ \__, |
|_| |___/
by @gwendallecoguic
""")
pass
banner()
parser = argparse.ArgumentParser()
parser.add_argument( "-o","--host",help="set hosts file list" )
parser.add_argument( "-t","--threads",help="threads, default 10" )
parser.add_argument( "-i","--ip",help="also store the ip address", action="store_true" )
parser.parse_args()
args = parser.parse_args()
if args.threads:
_threads = int(args.threads)
else:
_threads = 10
if args.ip:
_store_ip = True
else:
_store_ip = False
t_hosts = []
if args.host:
if os.path.isfile(args.host):
fp = open( args.host, 'r' )
t_hosts = fp.read().split("\n")
fp.close()
n_host = len(t_hosts)
if not n_host:
parser.error( 'hosts list missing' )
sys.stdout.write( '%s[+] %d hosts loaded: %s%s\n' % (fg('green'),n_host,args.host,attr(0)) )
def resolve( host, store_ip ):
host = host.strip()
if not len(host):
return
if t_multiproc['n_current']%5000 == 0:
save( store_ip )
sys.stdout.write( 'progress: %d/%d\r' % (t_multiproc['n_current'],t_multiproc['n_total']) )
t_multiproc['n_current'] = t_multiproc['n_current'] + 1
try:
ip = socket.gethostbyname( host )
t_alive[host] = ip
# print(ip)
except Exception as e:
t_dead.append( host )
# sys.stdout.write( "%s[-] error occurred: %s (%s)%s\n" % (fg('red'),e,host,attr(0)) )
t_alive = {}
t_dead = []
t_multiproc = {
'n_current': 0,
'n_total': n_host
}
# pool = Pool( _threads )
# pool.map( resolve, t_hosts )
# pool.close()
# pool.join()
def save( store_ip ):
fp = open( 'hosts_alive', 'w' )
for h in sorted(t_alive.keys()):
if store_ip:
fp.write( "%s:%s\n" % (h,t_alive[h]) )
else:
fp.write( "%s\n" % h )
fp.close()
fp = open( 'hosts_dead', 'w' )
for h in t_dead:
fp.write( "%s\n" % h )
fp.close()
def doWork():
while True:
host = q.get()
resolve( host, _store_ip )
q.task_done()
q = Queue( _threads*2 )
for i in range(_threads):
t = Thread( target=doWork )
t.daemon = True
t.start()
try:
for host in t_hosts:
q.put( host )
q.join()
except KeyboardInterrupt:
sys.exit(1)
# print( t_alive)
# print( t_dead)
sys.stdout.write( '%s[+] %d hosts alive, %d dead hosts%s\n' % (fg('green'),len(t_alive),len(t_dead),attr(0)) )
save( _store_ip )
exit()