package main import ( "fmt" "net" "time" ) // The host we will try to connect to. // ipv6.google.com is a good choice as it's highly available and resolves only to AAAA records (IPv6). const ipv6TestHost = "ipv6.google.com" const testPort = "443" // HTTPS port, almost always open. func IPv6test() (string, error) { // We use net.DialTimeout to attempt a TCP connection. // By specifying "tcp6" as the network, we force the dialer to use IPv6 only. // If the system can't resolve the AAAA record or can't route to the IPv6 address, // this will fail. timeout := 2 * time.Second conn, err := net.DialTimeout("tcp6", net.JoinHostPort(ipv6TestHost, testPort), timeout) // Check the result. if err != nil { // The connection failed. This indicates that IPv6 is not working correctly. return fmt.Sprintf("IPv6 connectivity test failed: %v"), err } // If we get here, the connection was successful. // It's good practice to close the connection we opened. conn.Close() return fmt.Sprintf("IPv6 connectivity test successful."), nil }