def get_ip(self, log, options): """Implement AddressPlugin.get_ip().""" addr = IpAddr() opts = dict_of_opts(options) if 'ip' not in opts and 'ip6' not in opts: raise AddressError('Required option ip= or ip6= missing, giving up.') if 'ip' in opts: addr.v4 = opts['ip'] if 'ip6' in opts: addr.v6 = opts['ip6'] return addr
def get_ip(self, log: Logger, options: [str]) -> Optional[IpAddr]: """Implements AddressPlugin.get_ip().""" urls = [DeDnshomeAddressURL.IP4, DeDnshomeAddressURL.IP6] ip = IpAddr(None, None) for url in urls: result = DeDnshomeWebPlugin.load_ip(log, url.value) if result: if not ip.v4 and result.v4: ip.v4 = result.v4 if not ip.v6 and result.v6: ip.v6 = result.v6 log.debug("Returning ip: " + str(ip)) return ip if not ip.empty() else None
def get_ip(self, log, options): """Implement AddressPlugin.get_ip().""" opts = dict_of_opts(options) if 'cmd' not in opts: raise AddressError('Required option cmd= missing, giving up.') cmd = opts['cmd'] log.debug('Running: %s', cmd) addr = IpAddr() result = subprocess.getoutput(cmd).strip() log.debug('result: %s', result) pat = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}') pat6 = re.compile(r'[:0-9a-f]{12,}(\s|\Z)') for word in result.split(): if pat.fullmatch(word): addr.v4 = word elif pat6.fullmatch(word): addr.v6 = word else: raise AddressError('Cannot parse command output: ' + result) return addr