mirror of
https://github.com/NewFuture/DDNS.git
synced 2022-04-19 20:24:44 +00:00
feat(index): 使用命令行输入作为目标IP
This commit is contained in:
@@ -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解析
|
||||
|
||||
#### 配置示例
|
||||
|
||||
+2
-3
@@ -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
|
||||
|
||||
|
||||
+1
-2
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user