Commit b59261eb authored by chiahetcho's avatar chiahetcho 💬

Initial commit

# -*- coding: utf-8 -*-
from threading import Thread
import queue
import subprocess
import datetime
import time
# defining some global variables
ips = ["", "","","",""]
dico_ips = {ips[0]: "firewall-adherents",
ips[1]: "switch-cdr",
ips[2]: "switch-cdr-vu-par-beta-testeurs",
ips[3]: "dns-cloudfare",
ips[4]: "derriere-firewall"}
num_threads = 2
ips_q = queue.Queue()
out_q = queue.Queue()
def thread_pinger(i, q):
# get an IP item from queue
while True:
ip = q.get()
# ping it
ping = subprocess.Popen(
["ping", str(ip)],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
# save the result
out, error = ping.communicate()
with open(dico_ips[ip]+'.txt','a') as file:
ts = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
file.write(ts + out.decode('cp437'))
if ping.wait() == 0 :
# update queue
while True:
# start the thread pool
for i in range(num_threads):
worker = Thread(target=thread_pinger, args=(i, ips_q))
# fill queue
for ip in ips:
# wait until worker threads are done to exit
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment