X-Git-Url: https://git.ralfj.de/dyn-nsupdate.git/blobdiff_plain/b3b6845d29bd9dda2717ef25ac9afd4d442f97ef..d95148544cb5f50e5aba884fd1f957182a9b70ca:/client-scripts/dyn-ns-client diff --git a/client-scripts/dyn-ns-client b/client-scripts/dyn-ns-client index 2923e06..2a5dc21 100755 --- a/client-scripts/dyn-ns-client +++ b/client-scripts/dyn-ns-client @@ -21,23 +21,20 @@ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# The views and conclusions contained in the software and documentation are those -# of the authors and should not be interpreted as representing official policies, -# either expressed or implied, of the FreeBSD Project. - -import urllib.request, socket, sys, argparse - +#============================================================================== # configuration variables -domains = ['domain.dyn.ralfj.de'] # list of domains to update -password = 'yourpassword' +domains = ['test.dyn.example.com'] # list of domains to update +password = 'some_secure_password' haveIPv4 = True haveIPv6 = False -serverIPv4 = 'ipv4.ns.ralfj.de' # Only needed if haveIPv4 is True. This server should NOT have an AAAA record! -serverIPv6 = 'ipv6.ns.ralfj.de' # Only needed if haveIPv6 is True. This server should NOT have an A record! -server = 'ns.ralfj.de' +serverIPv4 = 'ipv4.ns.example.com' # Only needed if haveIPv4 is True. This server should NOT have an AAAA record! +serverIPv6 = 'ipv6.ns.example.com' # Only needed if haveIPv6 is True. This server should NOT have an A record! +server = 'ns.example.com' # END of configuration variables +#============================================================================== + +import urllib.request, socket, sys, argparse def urlopen(url): return urllib.request.urlopen(url).read().decode('utf-8').strip() @@ -47,7 +44,8 @@ def getMyIP(server): def getCurIP(domain, family): try: - return socket.getaddrinfo(domain, None, family=family)[0][4][0] + addr = socket.getaddrinfo(domain, None, family=family) + return addr[0][4][0] except socket.gaierror: # domain not found return "" @@ -64,12 +62,14 @@ def update_domain(server, domain, ipv4, ipv6, password, verbose): # check what the domain is currently mapped to curIPv4 = getCurIPv4(domain) curIPv6 = getCurIPv6(domain) + if verbose: + print("Current status of domain {0} is: IPv4 address '{1}', IPv6 address '{2}'".format(domain, curIPv4, curIPv6)) # check if there's something to do needUpdate = (ipv4 is not None and curIPv4 != ipv4) or (ipv6 is not None and curIPv6 != ipv6) if not needUpdate: if verbose: - print("Everything alread up-to-date, nothing to do") + print("Everything already up-to-date, nothing to do") return True # we need to update the IP @@ -108,9 +108,20 @@ if __name__ == "__main__": help="The domains to update") args = parser.parse_args() - # get our own IPs - myIPv4 = getMyIP(serverIPv4) if haveIPv4 else None - myIPv6 = getMyIP(serverIPv6) if haveIPv6 else None + # get our own IPv4 + if haveIPv4: + myIPv4 = getMyIP(serverIPv4) + if args.verbose: + print("My IPv4 is",myIPv4) + else: + myIPv4 = None + # and IPv6 + if haveIPv6: + myIPv6 = getMyIP(serverIPv6) + if args.verbose: + print("My IPv6 is",myIPv6) + else: + myIPv6 = None # update all the domains exitcode = 0