view modules/net_mon/net_mon.py @ 47:190a81a60e7e tip

Update README G: changed README.txt
author Gernot Schulz <gernot@intevation.de>
date Sun, 07 Feb 2016 13:26:32 +0100
parents 1a13a4ecf931
children
line wrap: on
line source
#!/usr/bin/env python3

""" very simple network_monitoring. Derterminats if a remote machine
is available or not

author: Sean Engelhardt <sean.engelhardt@intevation.de>

This is Free Software unter the terms of the
GNU GENERAL PUBLIC LICENSE Version 2 or later.
See http://www.gnu.org/licenses/gpl-3.0.txt for details
"""

import socket, time, threading

interval = 5
ip = "212.95.122.133"
port = 80

def is_service_available(ip, port):
    server_available = False
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        s.connect((ip, port))
        server_available = True
    except socket.error:
        server_available = False
    s.close()
    return server_available

def check_service_regularly(interval, ip, port):
    is_available = is_service_available(ip, port)

    # return is_available
    print("Server " + ip + " ::: "+ str(is_available))
    threading.Timer(interval, check_service_regularly, [interval, ip, port]).start()

# print("server : " + str(check_service_regularly(5, "212.95.122.133", 80)))

check_service_regularly(interval, "212.95.122.133", 80)
check_service_regularly(interval, "127.0.0.1", 80)
check_service_regularly(interval, "127.0.0.1", 81)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)