示例#1
0
def start(host):
    try:
        host = host.replace('http://','').replace('https://','')
        HOST = ping(host)
        print(f'{host} {HOST}')
    except:
        pass
示例#2
0
文件: ping.py 项目: skripkar/noc
 def ping_check(self,
                address,
                size=64,
                count=1,
                timeout=1000,
                policy=CHECK_FIRST):
     """
     Perform ping check and return status
     :param address: IPv4/IPv6 address of host
     :param size: Packet size, in octets
     :param count: Maximal number of packets to send
     :param timeout: Ping timeout, in milliseconds
     :param policy: Check policy. CHECK_FIRST - return True on
         first success. CHECK_ALL - return True when all checks succeded
     :returns: Ping status as boolean
     """
     socket = self.get_socket(address)
     if not socket:
         raise tornado.gen.Return(None)
     req_id = next(self.iter_request) & 0xFFFF
     result = policy == self.CHECK_ALL and count > 0
     for seq in range(count):
         r = yield socket.ping(address, timeout, size, req_id, seq)
         if r and policy == self.CHECK_FIRST:
             result = True
             break
         elif not r and policy == self.CHECK_ALL:
             result = False
             break
     logger.debug("[%s] Result: %s", address, result)
     raise tornado.gen.Return(result)
示例#3
0
文件: ping.py 项目: skripkar/noc
 def ping_check_rtt(self,
                    address,
                    size=64,
                    count=1,
                    timeout=1000,
                    policy=CHECK_FIRST):
     """
     Perform ping check and return round-trip time
     :param address: IPv4/IPv6 address of host
     :param size: Packet size, in octets
     :param count: Maximal number of packets to send
     :param timeout: Ping timeout, in milliseconds
     :param policy: Check policy. CHECK_FIRST - return True on
         first success. CHECK_ALL - return True when all checks succeded
     :returns: rtt in seconds as float or None for failure
     """
     socket = self.get_socket(address)
     if not socket:
         raise tornado.gen.Return(None)
     req_id = next(self.iter_request) & 0xFFFF
     result = policy == self.CHECK_ALL and count > 0
     rtts = []
     attempt = 0
     for seq in range(count):
         rtt = yield socket.ping(address, timeout, size, req_id, seq)
         if rtt is not None:
             rtts += [rtt]
         if rtt and policy == self.CHECK_FIRST:
             result = True
             attempt = seq
             break
         elif not rtt and policy == self.CHECK_ALL:
             result = False
             break
     if result:
         rtt = sum(rtts) / len(rtts)
         if policy == self.CHECK_ALL:
             attempt = 0
         elif attempt > 0:
             metrics["ping_check_recover"] += 1
         logger.debug("[%s] Result: success, rtt=%s, attempt=%d", address,
                      rtt, attempt)
         raise tornado.gen.Return((rtt, attempt))
     else:
         logger.debug("[%s] Result: failed", address)
         raise tornado.gen.Return((None, attempt))