From 7f75b9578898ba64a43607e85324c15c097c30de Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 22 Jun 2014 10:44:09 +0000 Subject: [PATCH] Allow reading the local IP address from IPFire 2 systems. --- src/ddns/system.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/ddns/system.py b/src/ddns/system.py index be18d65..5885c63 100644 --- a/src/ddns/system.py +++ b/src/ddns/system.py @@ -61,6 +61,24 @@ class DDNSSystem(object): return proxy + def get_local_ipv6_address(self): + return # XXX TODO + + def get_local_ipv4_address(self): + if self.distro == "ipfire-2": + try: + with open("/var/ipfire/red/local-ipaddress") as f: + return f.readline() + + except IOError, e: + # File not found + if e.errno == 2: + return + + raise + + return # XXX TODO + def _guess_external_ip_address(self, url, timeout=10): """ Sends a request to an external web server @@ -213,8 +231,12 @@ class DDNSSystem(object): elif proto == "ipv4": return self.guess_external_ipv4_address() - # XXX TODO - assert False + # Get the local IP addresses. + else: + if proto == "ipv6": + return self.get_local_ipv6_address() + elif proto == "ipv4": + return self.get_local_ipv4_address() def resolve(self, hostname, proto=None): addresses = [] -- 2.39.2