Implemented ip change checking
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-05-08 22:21:15 +02:00
parent 7ce88f1a74
commit 0713cabc6b
3 changed files with 47 additions and 17 deletions

24
ip_watchdog.py Normal file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env python3
from typing import Tuple
import logging
import socket
from redis_super_storage import RedisSuperStorage
class IPWatchdog:
def __init__(self, redis_store: RedisSuperStorage):
self._redis_store = redis_store
self._host_name = socket.gethostname()
def ip_changed(self) -> Tuple[bool, str]:
old_ip = self._redis_store.current_ip
current_ip = socket.gethostbyname(self._host_name)
if current_ip != old_ip:
logging.info(f'IP changed: {old_ip} -> {current_ip}')
self._redis_store.current_ip = current_ip
return True, current_ip
return False, old_ip