From ed407ffb6111e6bef9b93ebbadbfe0bbda3f6437 Mon Sep 17 00:00:00 2001 From: Jason McCormick Date: Mon, 2 Nov 2026 20:57:55 -0500 Subject: add --initialize-state --- he-dyndns | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'he-dyndns') diff --git a/he-dyndns b/he-dyndns index e4bfd39..18a5932 100755 --- a/he-dyndns +++ b/he-dyndns @@ -215,6 +215,11 @@ def make_parser(): "--state-file", default=DEFAULT_STATE_FILE, help="local comparison state (default: %(default)s)", ) + parser.add_argument( + "--initialize-state", + action="store_true", + help="record the current IPv4 and IPv6 addresses, then exit without updating HE", + ) parser.add_argument( "--keyfile", default="/etc/he-dyndns.conf", help="key config file (default: %(default)s)", @@ -226,6 +231,29 @@ def make_parser(): def run(args, parser): + if args.initialize_state: + if args.v4 or args.v6 or args.addr4 or args.addr6: + parser.error( + "--initialize-state cannot be combined with address-family or explicit-address options" + ) + with state_lock(args.state_file): + addresses = { + str(version): str( + discover_address(args.check_url, version, timeout=args.timeout) + ) + for version in (4, 6) + } + state = read_state(args.state_file) + state[args.record] = addresses + write_state(args.state_file, state) + log.debug( + "initialized state for %s: IPv4 %s, IPv6 %s", + args.record, + addresses["4"], + addresses["6"], + ) + return + version = selected_version(args, parser) explicit_value = args.addr4 if version == 4 else args.addr6 key = args.key if args.key is not None else get_key(args.keyfile, args.record) -- cgit v1.2.3