#!/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