2020-11-14 11:46:19 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2023-09-23 14:42:00 +00:00
|
|
|
import logging
|
|
|
|
from ipaddress import ip_address
|
|
|
|
from json import loads
|
|
|
|
from subprocess import check_output
|
2020-11-14 11:46:19 +00:00
|
|
|
|
2023-09-23 14:42:00 +00:00
|
|
|
from requests import get
|
2023-02-05 16:30:58 +00:00
|
|
|
|
2020-11-14 11:46:19 +00:00
|
|
|
|
|
|
|
UPDATE_URL = '${url}'
|
|
|
|
USERNAME = '${username}'
|
|
|
|
PASSWORD = '${password}'
|
|
|
|
|
2023-09-23 14:42:00 +00:00
|
|
|
# <%text>
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
LOG = logging.getLogger('DynDNS')
|
|
|
|
try:
|
|
|
|
ips = set()
|
|
|
|
|
|
|
|
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,
|
|
|
|
),
|
2020-11-14 11:46:19 +00:00
|
|
|
)
|
2023-09-23 14:42:00 +00:00
|
|
|
r.raise_for_status()
|
|
|
|
except Exception as e:
|
|
|
|
logging.exception(e)
|
2020-11-14 11:46:19 +00:00
|
|
|
|
2023-09-23 14:42:00 +00:00
|
|
|
# </%text>
|