Development
This commit is contained in:
parent
7e39b077d1
commit
275ccd0bac
2 changed files with 41 additions and 33 deletions
|
|
@ -210,11 +210,17 @@ def _get_ip_via_http(spec):
|
|||
return _extract_ip(r.read().decode().strip())
|
||||
|
||||
|
||||
_SAFE_DIG_RE = re.compile(r'^[a-zA-Z0-9.\-_@+:\s]+$')
|
||||
|
||||
def _get_ip_via_dig(spec):
|
||||
"""Query public IP via dig. spec: {"type": "dig", "command": "<dig args>"}
|
||||
"""Query public IP via dig. spec: {"type": "dig", "url": "<dig args>"}
|
||||
Requires the 'dig' utility to be installed.
|
||||
"""
|
||||
cmd = ["dig", "+short"] + spec["url"].split()
|
||||
url = spec["url"]
|
||||
if not _SAFE_DIG_RE.match(url):
|
||||
log.warning(f"Skipping dig service with disallowed characters: {url!r}")
|
||||
return None
|
||||
cmd = ["dig", "+short"] + url.split()
|
||||
try:
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
|
||||
if result.returncode != 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue