ddns-updater icon indicating copy to clipboard operation
ddns-updater copied to clipboard

Feature request: determine if ipv4 and/or ipv6 should be updated

Open qdm12 opened this issue 3 years ago • 3 comments

  • Automatically detect if the machine supports ipv4 and/or ipv6 and depending on that gets its public IP address.
  • Update records with ipv4 and/or ipv6 depending on the result above
  • Remove the ip_version parameter

The following can be used to detect ip version stacks supported:

func ipVersionsSupported(ctx context.Context) (ipv4, ipv6 bool) {
	dialer := &net.Dialer{}
	_, err := dialer.DialContext(ctx, "tcp4", "127.0.0.1:0")
	ipv4 = err.Error() == "dial tcp4 127.0.0.1:0: connect: connection refused"
	_, err = dialer.DialContext(ctx, "tcp6", "[::1]:0")
	ipv6 = err.Error() == "dial tcp6 [::1]:0: connect: connection refused"
	return ipv4, ipv6
}

qdm12 avatar Mar 21 '21 13:03 qdm12

Maybe let the ip_version optional in case the docker container is listening on a IPv4 interface but the machine also has an IPv6? But maybe this case would be too rare? What do you think?

fredericrous avatar May 18 '21 22:05 fredericrous

I.... need to test things more 😄 I don't have IPv6 enabled on my network... yet, although my ISP supports it so that's that I have to do.

If you have IPv6 (check for example here), can you try save the following as main.go

package main

import (
	"context"
	"fmt"
	"net"
)

func main() {
	ctx := context.Background()
	dialer := &net.Dialer{}
	_, err := dialer.DialContext(ctx, "tcp4", "127.0.0.1:0")
	ipv4 := err.Error() == "dial tcp4 127.0.0.1:0: connect: connection refused"
	fmt.Println("IPV4: ", ipv4)

	_, err = dialer.DialContext(ctx, "tcp6", "[::1]:0")
	ipv6 := err.Error() == "dial tcp6 [::1]:0: connect: connection refused"
	fmt.Println("IPV6: ", ipv6)
}

And run it with go run main.go on your host first? If you don't have IPv6, well we're both stuck for now 😄

qdm12 avatar May 19 '21 01:05 qdm12

These issues seem to overlap https://github.com/qdm12/ddns-updater/issues/507

tcurdt avatar Sep 04 '23 20:09 tcurdt