Created
October 31, 2021 13:00
-
-
Save 97997/30e3f1c1ffbc7ad34ab4647703bcafbe to your computer and use it in GitHub Desktop.
uptime and ip monitoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import system, name | |
from time import sleep | |
from requests import get | |
from tkinter import messagebox | |
# TODO Guardar variable a un archivo, checar el archivo frecuentemente, si se detecta un cambio de ip, enviar email | |
def render(): | |
# ctypes required for using GetTickCount64() | |
import ctypes | |
# getting the library in which GetTickCount64() resides | |
lib = ctypes.windll.kernel32 | |
# calling the function and storing the return value | |
t = lib.GetTickCount64() | |
# since the time is in milliseconds i.e. 1000 * seconds | |
# therefore truncating the value | |
t = int(str(t)[:-3]) | |
# extracting hours, minutes, seconds & days from t | |
# variable (which stores total time in seconds) | |
mins, sec = divmod(t, 60) | |
hour, mins = divmod(mins, 60) | |
days, hour = divmod(hour, 24) | |
# formatting the time in readable form | |
# (format = x days, HH:MM:SS) | |
print("Uptime: ", end="") | |
print(f"{days} days, {hour:02}:{mins:02}:{sec:02}") | |
# This example requires the requests library be installed. You can learn more | |
# about the Requests library here: http://docs.python-requests.org/en/latest/ | |
ip = get('https://api.ipify.org').content.decode('utf8') | |
print('My public IP address is: {}'.format(ip)) | |
f = open("ip.txt", "r") | |
readedip = f.read() | |
f.close() | |
if not readedip == ip: | |
msg = str(readedip) + " -> " + str(ip) | |
messagebox.showinfo("IP Changed", msg) | |
f = open("ip.txt", "w") | |
f.write(str(ip)) | |
f.close() | |
def clear(): | |
# for windows | |
if name == 'nt': | |
_ = system('cls') | |
# for mac and linux(here, os.name is 'posix') | |
else: | |
_ = system('clear') | |
def printTime(): | |
import datetime | |
now = datetime.datetime.now() | |
print("Current date and time: ", end="") | |
print(str(now)) | |
while True: | |
printTime() | |
render() | |
sleep(60*30) | |
clear() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment