Last active
June 3, 2019 07:22
-
-
Save lufia/0cb0544ac7bb060c99f36f838bf1b6dd to your computer and use it in GitHub Desktop.
ホスト直接指定してTLS暗号スイートを確認する方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/tls" | |
"flag" | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
) | |
var ( | |
flagHost = flag.String("h", "", "hostname to overwrite") | |
) | |
func usage() { | |
w := flag.CommandLine.Output() | |
fmt.Fprintf(w, "usage: %v [options] [url ...]\n", os.Args[0]) | |
flag.PrintDefaults() | |
os.Exit(2) | |
} | |
func main() { | |
log.SetFlags(0) | |
flag.Usage = usage | |
flag.Parse() | |
if *flagHost != "" { | |
t := http.DefaultTransport.(*http.Transport) | |
t.TLSClientConfig = &tls.Config{ | |
ServerName: *flagHost, | |
} | |
} | |
for _, url := range flag.Args() { | |
req, err := http.NewRequest("GET", url, nil) | |
if err != nil { | |
log.Println("can't create a request:", err) | |
continue | |
} | |
if *flagHost != "" { | |
req.Host = *flagHost | |
} | |
resp, err := http.DefaultClient.Do(req) | |
if err != nil { | |
log.Printf("can't fetch from %s: %v", url, err) | |
continue | |
} | |
defer resp.Body.Close() | |
fmt.Printf("CipherSuite: %x\n", resp.TLS.CipherSuite) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment