zoukankan      html  css  js  c++  java
  • 监测主机存活python小脚本

    监测主机存活python小脚本

    @(coding)[python,笔记]

    此脚本用于监测主机存活性。原理:通过向目标主机发送icmp数据包测试,通过python循环和定时任务来完成,很简单。IP替换为监测主机ip,3是设置的时间,每三秒监测一次。

    # --*-- coding:utf-8 --*--
    import os
    from datetime import datetime
    import time
    
    os.system('chcp 65001')    #解决cmd下出现乱码问题
     
    def timer(t=5):
        while True:
            print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
            status=os.system("ping -n 1 IP")
            if status == 0 :
            	print ("alive"*2)
            else:
            	print ("dead"*8)
            	str1 = "The host is HALT at "+datetime.now().strftime("%Y-%m-%d %H:%M:%S")+'status'
            	fp=open("dead_Time.txt",a)
            	fp.write(str1)
            	fp.close()
            time.sleep(t)
    
    timer(3)
    记得旧文章 便是新举子
  • 相关阅读:
    洛谷 [SDOI2015]约数个数和 解题报告
    multiset-count
    multiset-begin
    multiset-begin
    set-value_comp
    set-value_comp
    multiset-constructors
    multiset-constructors
    set-upper_bound
    set-upper_bound
  • 原文地址:https://www.cnblogs.com/NBeveryday/p/9474561.html
Copyright © 2011-2022 走看看