sean@20: #!/usr/bin/env python3 sean@20: sean@20: """ very simple network_monitoring. Derterminats if a remote machine sean@20: is available or not sean@20: sean@20: author: Sean Engelhardt sean@20: sean@20: This is Free Software unter the terms of the sean@20: GNU GENERAL PUBLIC LICENSE Version 2 or later. sean@20: See http://www.gnu.org/licenses/gpl-3.0.txt for details sean@20: """ sean@20: sean@20: import socket, time, threading sean@20: sean@20: interval = 5 sean@20: ip = "212.95.122.133" sean@20: port = 80 sean@20: sean@20: def is_service_available(ip, port): sean@20: server_available = False sean@20: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sean@20: try: sean@20: s.connect((ip, port)) sean@20: server_available = True sean@20: except socket.error: sean@20: server_available = False sean@20: s.close() sean@20: return server_available sean@20: sean@20: def check_service_regularly(interval, ip, port): sean@20: is_available = is_service_available(ip, port) sean@20: sean@20: # return is_available sean@20: print("Server " + ip + " ::: "+ str(is_available)) sean@20: threading.Timer(interval, check_service_regularly, [interval, ip, port]).start() sean@20: sean@20: # print("server : " + str(check_service_regularly(5, "212.95.122.133", 80))) sean@20: sean@20: check_service_regularly(interval, "212.95.122.133", 80) sean@20: check_service_regularly(interval, "127.0.0.1", 80) sean@20: check_service_regularly(interval, "127.0.0.1", 81)