// +build ignore package main import ( "fmt" "log" "net" "net/http" ) func main() { for _, host := range []string{"www.example.com", "www.google.com"} { inSeries(host) inParallel(host) } } func inSeries(host string) { fn := func(network, address string) (net.Conn, error) { c, err := net.Dial(network, address) if err == nil { log.Println("!", host, c.LocalAddr(), "->", c.RemoteAddr()) } return c, err } addrs, err := net.LookupHost(host) if err != nil { log.Println("?", host, err) return } tr := &http.Transport{Dial: fn} client := http.Client{Transport: tr} for _, a := range addrs { resp, err := client.Get(fmt.Sprintf("http://%s/", net.JoinHostPort(a, "80"))) if err != nil { log.Println("?", host, err) continue } log.Println(host, "connected to", resp.Request.URL.Host) resp.Body.Close() } } func inParallel(host string) { fn := func(network, address string) (net.Conn, error) { d := net.Dialer{DualStack: true} c, err := d.Dial(network, address) if err == nil { log.Println("!!", host, c.LocalAddr(), "->", c.RemoteAddr()) } return c, err } tr := &http.Transport{Dial: fn} client := http.Client{Transport: tr} resp, err := client.Get(fmt.Sprintf("http://%s/", host)) if err != nil { log.Println("??", host, err) return } log.Println(host, "connected to", resp.Request.URL.Host) resp.Body.Close() }