From d70390197ee3e06ee1fecbc14d1ed48ba4040c94 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 28 Sep 2019 19:30:41 +0200 Subject: Initial commit --- pykeepalive.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 pykeepalive.py (limited to 'pykeepalive.py') diff --git a/pykeepalive.py b/pykeepalive.py new file mode 100644 index 0000000..e4d54af --- /dev/null +++ b/pykeepalive.py @@ -0,0 +1,42 @@ +#/bin/python3 + +import sys, time +import tailhead + +from config import * + +import tools +import commands +import file +import log + +if len(sys.argv) == 1: + log.tail_log() + if commands.multi_ping(HOSTS, INTERFACE) == 0: + file.log_write("ONLINE") + else: + print("Ooops, we're offline!") + file.log_write("OFFLINE >> RESETING INTERFACE [{}]".format(INTERFACE)) + print(">> Reseting interface [{}]...".format(INTERFACE)) + ip, gateway, subnet = commands.uqmi_current_settings() + commands.ifconfig_update(INTERFACE, ip, subnet) + commands.route_update(gateway) +elif len(sys.argv) == 2: + if sys.argv[1] == "tail": + log.tail_log() + for line in tailhead.follow_path(LOG_PATH_FILE): + if line is not None: + print(tools.status_color(line)) + else: + time.sleep(1) + elif sys.argv[1] == "cat": + log.tail_log() + with open(LOG_PATH_FILE) as f: + for line in f: + print(tools.status_color(line), end="") + else: + tools.show_help() +else: + tools.show_help() + + -- cgit v1.2.1