解決python 服務端口探測探活

import os
import threading

def check_client_status(ip, port):
    if os.system('nc -i 1 -w 1 {0} {1}'.format(ip, port)) != 0:
        print "{0} {1}".format(ip, port)

def start_check():
    print "mega clients is down:"
    ins_ips = [(ip, port), ...]  # ip列表
    thread_list = list()
    for ip, port in ins_ips:
       thread_list.append(threading.Thread(target=check_client_status, args=(ip, port)))
       
    for thread in thread_list:
       thread.start()

    for thread in thread_list:
       thread.join()
       
    print "check all clients status complete!"
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章