summaryrefslogtreecommitdiff
path: root/ipv6test.go.new
diff options
context:
space:
mode:
Diffstat (limited to 'ipv6test.go.new')
-rw-r--r--ipv6test.go.new55
1 files changed, 55 insertions, 0 deletions
diff --git a/ipv6test.go.new b/ipv6test.go.new
new file mode 100644
index 0000000..c9d814e
--- /dev/null
+++ b/ipv6test.go.new
@@ -0,0 +1,55 @@
+package main
+
+import (
+ "context"
+ "fmt"
+ "net"
+ "os"
+ "time"
+)
+
+const (
+ ipv6TestHost = "ipv6.google.com"
+ testPort = "443" // HTTPS port
+)
+
+func main() {
+ // --- Step 1: Fast DNS Lookup ---
+ // We'll use a separate, short timeout just for the DNS resolution.
+ // If DNS is broken, we'll know in a second or two.
+ dnsTimeout := 2 * time.Second
+ ctx, cancel := context.WithTimeout(context.Background(), dnsTimeout)
+ defer cancel()
+
+ // net.DefaultResolver.LookupIPAddr forces the resolver to look up the host.
+ // We specify "ip6" to ensure we only get AAAA records.
+ addrs, err := net.DefaultResolver.LookupIPAddr(ctx, "ip6", ipv6TestHost)
+ if err != nil {
+ fmt.Printf("IPv6 DNS resolution failed: %v\n", err)
+ fmt.Println("This likely means your network cannot resolve IPv6 addresses.")
+ os.Exit(1)
+ }
+
+ if len(addrs) == 0 {
+ fmt.Printf("No IPv6 addresses found for %s\n", ipv6TestHost)
+ os.Exit(1)
+ }
+
+ // If we get here, DNS is working. Let's use the first address we found.
+ targetIP := addrs[0].IP.String()
+ fmt.Printf("Successfully resolved %s to IPv6 address: %s\n", ipv6TestHost, targetIP)
+
+ // --- Step 2: Connection Attempt ---
+ // Now we try to connect to the IP we found. This tests routing and firewalls.
+ connectionTimeout := 3 * time.Second
+ conn, err := net.DialTimeout("tcp6", net.JoinHostPort(targetIP, testPort), connectionTimeout)
+ if err != nil {
+ fmt.Printf("IPv6 connection to %s failed: %v\n", targetIP, err)
+ fmt.Println("This likely means your network has an IPv6 routing or firewall issue.")
+ os.Exit(1)
+ }
+ defer conn.Close()
+
+ fmt.Println("IPv6 connectivity test successful.")
+ os.Exit(0)
+}