美文网首页
一个测试多个IP的网络连通性小脚本(微信通知告警)

一个测试多个IP的网络连通性小脚本(微信通知告警)

作者: 獨孤記憶 | 来源:发表于2018-09-05 15:09 被阅读0次
image.png
image.png
import os
import time
import requests

PING_RESULT = 0
NETWORK_RESULT = 0

def DisableNetwork():
    result = os.system(u"netsh interface set interface 以太网 disable")
    if result == 1:
        print("disable network card failed")
    else:
        print("disable network card successfully")

def make_message(msg):
    return f'https://sc.ftqq.com/SCU23486T20f48c74769f0c6b72a918fe892307655ab14c6616304.send?text=庞銮先生你好!~&desp={msg}'

def ping():
    ip = ['ping 192.168.2.1','ping 192.168.2.2','ping 192.168.2.3',
          'ping 192.168.2.4','ping 192.168.2.5']

    for i in ip:
        result = os.system(i)
    # result = os.system(u"ping www.baidu.com -n 3")
        if result == 0:
            print(i+"网络正常")
        else:
            requests.post(make_message(i+'出现了网络故障'))
            print(i+"网络故障")
    return result


if __name__ == '__main__':
    while True:
        PING_RESULT = ping()

        if PING_RESULT == 0:
            time.sleep(20)
        else:
            time.sleep(10)

相关文章

网友评论

      本文标题:一个测试多个IP的网络连通性小脚本(微信通知告警)

      本文链接:https://www.haomeiwen.com/subject/bapawftx.html