Skip to content

Instantly share code, notes, and snippets.

@hsqStephenZhang
Created January 25, 2025 15:32
Show Gist options
  • Select an option

  • Save hsqStephenZhang/464792650322426c619ace61bdbc5ff5 to your computer and use it in GitHub Desktop.

Select an option

Save hsqStephenZhang/464792650322426c619ace61bdbc5ff5 to your computer and use it in GitHub Desktop.
golang utls fingerprint
// to start the project:
// go mod init
// go get -u github.com/imroc/req/v3
package main
import (
"flag"
"fmt"
"os"
"github.com/imroc/req/v3"
tls "github.com/refraction-networking/utls"
)
func main() {
// Define a command-line argument to accept the desired fingerprint
fingerprintArg := flag.String("fingerprint", "chrome", "Specify the fingerprint (e.g., chrome, edge, firefox, safari)")
flag.Parse()
// Map of fingerprints to their corresponding utls ClientHelloID
fingerprintMap := map[string]tls.ClientHelloID{
"chrome": tls.HelloChrome_115_PQ,
"edge": tls.HelloEdge_106,
"firefox": tls.HelloFirefox_105,
"safari": tls.HelloSafari_16_0,
"ios": tls.HelloIOS_14,
}
// Match the provided argument to a fingerprint
fingerprintID, exists := fingerprintMap[*fingerprintArg]
if !exists {
fmt.Fprintf(os.Stderr, "Invalid fingerprint: %s\n", *fingerprintArg)
fmt.Fprintf(os.Stderr, "Available fingerprints: chrome, edge, firefox, safari\n")
os.Exit(1)
}
// Create the HTTP client with the specified fingerprint
client := req.C().
SetUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36").
SetTLSFingerprint(fingerprintID)
// Make a GET request
res, err := client.R().Get("https://tls.peet.ws/api/all")
if err != nil {
fmt.Printf("Request failed: %v\n", err)
os.Exit(1)
}
// Print the response
fmt.Println(res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment