2011|08|
2013|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|05|06|07|08|09|10|11|12|
2016|01|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|

2019-07-02 ping風にWebサーバの生死を監視するツール [長年日記]

#!/usr/bin/python
# coding: UTF-8
#
# Webサーバ 生死監視ツール
#
# ping風にサーバを見たかったので作ってみた
# 
# 起動例
# $ python3 webping.py
 
 
import http.client,datetime,os
import time
 
result = ""
 
#結果の書式
def format_result(address,response):
    return address +"  "+ str(response.status) + "  " + response.reason
 
#サーバをチェックする
def checkserver(address):
    global result 
 
    time.sleep(1)
    conn = http.client.HTTPConnection( address, timeout = 10 )
    try:
        conn.request( "GET", "/" )
    except:
        result = str(datetime.datetime.now()) + " " + result + address + " not found."
        print(result)
        result = "";
 
        return
    response = conn.getresponse()
    result = now = str(datetime.datetime.now()) + " " + result + format_result(address,response)
    print(result)
    result = "";
 
    conn.close()
 
# ここでサーバをチェックする
 
while 1:
    # checkserver("kobore.net")
    checkserver("localhost")
syntax2html