from threading import Thread from urllib request import urlopen from q

 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
from threading import Thread
from urllib.request import urlopen
from queue import Queue, Empty
def thread_network(taskq):
while True:
try:
url = taskq.get(block=False)
except Empty:
return
else:
try:
urlopen(url).read()
except Exception as ex:
print('[FAIL] %s: %s' % (url, ex))
else:
print('[OK] %s' % url)
def main():
taskq = Queue()
with open('var/ips10k.txt') as inp:
count = 0
for line in inp:
ip = line.strip()
taskq.put('https://%s' % ip)
count += 1
if count >= 100:
break
pool = []
for _ in range(10):
th = Thread(target=thread_network, args=[taskq])
th.start()
pool.append(th)
[x.join() for x in pool]
if __name__ == '__main__':
main()