def status(cls, host): msg = "Unknown host" try: msg = Shell.ping("-c", "1", host) except: pass if "1 packets transmitted, 1 packets received" in msg: return True elif "Unknown host" in msg: return False else: return False
def ping(host): """ping the specified host. :param host: the name or ip of the host """ try: result = Shell.ping("-o", "-c", "1", host).strip().split("\n") except: pass try: (attributes, values) = result[-1].replace("round-trip", "")\ .strip().split("=") attributes = attributes.strip().split("/") values = values.strip().split("/") data = dict(zip(attributes, values)) data['loss'] = result[-2].split(",")[2].split("%")[0].strip() + "%" except: data = {} data['host'] = host return data