-
Notifications
You must be signed in to change notification settings - Fork 52
/
getHostsFile.py
36 lines (33 loc) · 917 Bytes
/
getHostsFile.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
import os
import sys
import socket
import threading
from lib import synchronizedOutput, synchronizedQueue
class myThread(threading.Thread) :
def __init__(self, queue, output) :
threading.Thread.__init__(self)
self.queue = queue
self.output = output
def run(self) :
while True :
cur = self.queue.get()
if (cur == None) : break
try :
result = socket.gethostbyname(cur)
self.output.out(result + '\t' + cur)
except : pass
if len(sys.argv) != 2 :
print sys.argv[0] + ' <Input File>'
else :
q = synchronizedQueue()
out = synchronizedOutput()
f = file(sys.argv[1])
for line in f.readlines() :
q.put(line[ : -1])
threads = list()
for i in range(0, 5) :
t = myThread(q, out)
t.start()
threads.append(t)
for t in threads :
t.join()