Skip to content

Instantly share code, notes, and snippets.

@myleshorton
Created March 28, 2022 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myleshorton/1d79a9f444d1c0fabfb3a9e94400bc17 to your computer and use it in GitHub Desktop.
Save myleshorton/1d79a9f444d1c0fabfb3a9e94400bc17 to your computer and use it in GitHub Desktop.
Using TLS without DNS
package main
import (
"context"
"crypto/tls"
"fmt"
"net"
"net/http"
)
func main() {
client := &http.Client{
Transport: &http.Transport{
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
conf := &tls.Config{
ServerName: "google.com",
}
return tls.Dial("tcp", "142.250.64.110:443", conf)
},
},
}
res, err := client.Get("https://google.com")
if err != nil {
fmt.Printf("%v\n", err)
return
}
defer res.Body.Close()
fmt.Printf("%s\n", res.Status)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment