diff --git a/README.md b/README.md index 78fe9b7..612596c 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,8 @@ python run.py -c /path/to/config.json * 如果想匹配`10.00.xxxx`应该写成`"10\\.00\\..*"`(`"\\"`json转义成`\`) * 字符串`"default"`(或者无此项): 系统访问外网默认IP * 字符串`"public"`: 使用公网ip(使用公网API查询) +* 字符串`"cmd:xxxx"`: 执行命令`xxxx`的stdout输出结果作为目标IP +* 字符串`"shell:xxx"`: 使用系统shell运行`xxx`,并把结果stdout作为目标IP * `false`: 强制禁止更新ipv4或ipv6的DNS解析 #### 配置示例 diff --git a/dns/dnspod.py b/dns/dnspod.py index c4fb54e..1156405 100644 --- a/dns/dnspod.py +++ b/dns/dnspod.py @@ -69,6 +69,7 @@ def get_domain_info(domain): 切割域名获取主域名和对应ID """ domain_split = domain.split('.') + sub = '@' # root domain根域名https://github.com/NewFuture/DDNS/issues/9 if len(domain_split) == 3: # 长度为3 sub, main = domain_split[0], domain_split[1] + '.' + domain_split[2] did = get_domain_id(main) @@ -82,9 +83,7 @@ def get_domain_info(domain): break else: warning('domain_id: %s, sub: %s', did, sub) - return None, None - if not sub: # root domain根域名https://github.com/NewFuture/DDNS/issues/9 - sub = '@' + return None, None info('domain_id: %s, sub: %s', did, sub) return did, sub diff --git a/dns/dnspod_com.py b/dns/dnspod_com.py index 8398cd9..0e037de 100644 --- a/dns/dnspod_com.py +++ b/dns/dnspod_com.py @@ -73,6 +73,7 @@ def get_domain_info(domain): 切割域名获取主域名和对应ID """ domain_split = domain.split('.') + sub = '@' # root domain根域名https://github.com/NewFuture/DDNS/issues/9 if len(domain_split) == 3: # 长度为3 sub, main = domain_split[0], domain_split[1] + '.' + domain_split[2] did = get_domain_id(main) @@ -87,8 +88,6 @@ def get_domain_info(domain): else: warning('domain_id: %s, sub: %s', did, sub) return None, None - if not sub: # root domain根域名https://github.com/NewFuture/DDNS/issues/9 - sub = '@' return did, sub diff --git a/run.py b/run.py index e0f8e9c..93b6d54 100755 --- a/run.py +++ b/run.py @@ -12,6 +12,7 @@ from time import ctime from os import path, environ, stat, name as os_name from tempfile import gettempdir from logging import DEBUG, basicConfig, info, warning, error +from subprocess import check_output import sys @@ -84,6 +85,10 @@ def get_ip(ip_type): return False elif str(index).isdigit(): # local eth value = getattr(ip, "local_v" + ip_type)(index) + elif index.startswith('cmd:'): # cmd + value = check_output(index[4:]).strip() + elif index.startswith('shell:'): # shell + value = check_output(index[6:], shell=True).strip() elif any((c in index) for c in '*.:'): # regex value = getattr(ip, "regex_v" + ip_type)(index) else: