Implemented ip change checking
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
24
ip_watchdog.py
Normal file
24
ip_watchdog.py
Normal 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
|
Reference in New Issue
Block a user