home.router: let dyndns have ipv6 please
This commit is contained in:
parent
951d254c7a
commit
d999895450
6 changed files with 100 additions and 76 deletions
|
@ -1,24 +1,59 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from sys import argv
|
||||
import logging
|
||||
from ipaddress import ip_address
|
||||
from json import loads
|
||||
from subprocess import check_output
|
||||
|
||||
import requests
|
||||
from requests import get
|
||||
|
||||
INTERFACE = argv[1]
|
||||
LOCAL_IP = argv[4]
|
||||
|
||||
UPDATE_URL = '${url}'
|
||||
USERNAME = '${username}'
|
||||
PASSWORD = '${password}'
|
||||
|
||||
r = requests.get(
|
||||
UPDATE_URL.format(
|
||||
ip=LOCAL_IP,
|
||||
),
|
||||
auth=(
|
||||
USERNAME,
|
||||
PASSWORD,
|
||||
)
|
||||
)
|
||||
# <%text>
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
LOG = logging.getLogger('DynDNS')
|
||||
try:
|
||||
ips = set()
|
||||
|
||||
print('got status {} when updating dns'.format(r.status_code))
|
||||
iproute = loads(check_output(['ip', '-json', 'address', 'show', 'scope', 'global']))
|
||||
|
||||
for iface in iproute:
|
||||
if not iface['ifname'].startswith('ppp'):
|
||||
LOG.debug(f'ignoring {iface["ifname"]}')
|
||||
continue
|
||||
|
||||
LOG.info(f'working on {iface["ifname"]}')
|
||||
for ip in iface['addr_info']:
|
||||
try:
|
||||
addr = ip_address(ip['local'])
|
||||
|
||||
LOG.info(f'{iface["ifname"]} has ip {addr.compressed}')
|
||||
ips.add(addr.compressed)
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
if ips:
|
||||
LOG.info('got some addresses!')
|
||||
break
|
||||
|
||||
url = UPDATE_URL.format(
|
||||
ips=','.join(sorted(ips))
|
||||
)
|
||||
|
||||
LOG.info(url)
|
||||
|
||||
r = get(
|
||||
url,
|
||||
auth=(
|
||||
USERNAME,
|
||||
PASSWORD,
|
||||
),
|
||||
)
|
||||
r.raise_for_status()
|
||||
except Exception as e:
|
||||
logging.exception(e)
|
||||
|
||||
# </%text>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue