ddns-updater
ddns-updater copied to clipboard
Feature request: determine if ipv4 and/or ipv6 should be updated
- 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
}
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?
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 😄
These issues seem to overlap https://github.com/qdm12/ddns-updater/issues/507