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()