測試ping小程序

#!/usr/bin/env pythonpython

import os,sys,reshell

import subprocesside

import threadingip



nameList = eval(sys.argv[1])it


def runCheck(file_obj):class

    for host in file_obj:thread

        host = host.strip('\n')import

        p = subprocess.Popen(["ping -c 1 "+ host],List

                            stdin = subprocess.PIPE,file

                            stdout = subprocess.PIPE,

                            stderr = subprocess.PIPE,

                            shell = True)

        out = p.stdout.read()

        regex = re.compile("time=\d*", re.IGNORECASE | re.MULTILINE)

        if len(regex.findall(out)) > 0:

            print host+': Host Up!'

        else:

            print host+': Host Down!'





runCheck(nameList)

相關文章
相關標籤/搜索