forked from ipfire/ddns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddns.in
97 lines (75 loc) · 3.63 KB
/
ddns.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python
###############################################################################
# #
# ddns - A dynamic DNS client for IPFire #
# Copyright (C) 2012 IPFire development team #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
import argparse
import ddns
from ddns.i18n import _
CONFIGURATION_FILE = "@configsdir@/ddns.conf"
def main():
# Parse command line
p = argparse.ArgumentParser(description=_("Dynamic DNS Updater"))
p.add_argument("-d", "--debug", action="store_true",
help=_("Enable debugging output"))
p.add_argument("-c", "--config", default=CONFIGURATION_FILE,
help=_("Load configuration file (Default: %s)") % CONFIGURATION_FILE)
# Create subparsers for commands.
subparsers = p.add_subparsers(help=_("Sub-command help"),
dest="subparsers_name")
# guess-ip-addresses
p_guess_ip_addresses = subparsers.add_parser("guess-ip-addresses",
help=_("Guess the external IP addresses"))
# list-providers
p_list_providers = subparsers.add_parser("list-providers",
help=_("List all available providers"))
# update
p_update = subparsers.add_parser("update", help=_("Update DNS record"))
p_update.add_argument("hostname")
p_update.add_argument("--force", action="store_true",
help=_("Execute update even if the record is already up to date"))
# update-all
p_update_all = subparsers.add_parser("update-all", help=_("Update all DNS records"))
p_update_all.add_argument("--force", action="store_true",
help=_("Execute update even if the record is already up to date"))
args = p.parse_args()
# Initialise the DDNSCore module.
d = ddns.DDNSCore(debug=args.debug)
# Load configuration.
if args.config:
d.load_configuration(args.config)
# Handle commands...
if args.subparsers_name == "guess-ip-addresses":
# IPv6
ipv6_address = d.system.guess_external_ip_address("ipv6")
if ipv6_address:
print _("IPv6 Address: %s") % ipv6_address
# IPv4
ipv4_address = d.system.guess_external_ip_address("ipv4")
if ipv4_address:
print _("IPv4 Address: %s") % ipv4_address
elif args.subparsers_name == "list-providers":
provider_names = d.get_provider_names()
print "\n".join(provider_names)
elif args.subparsers_name == "update":
d.updateone(hostname=args.hostname, force=args.force)
elif args.subparsers_name == "update-all":
d.updateall(force=args.force)
else:
raise RuntimeError("Unhandled command: %s" % args.subparsers_name)
main()