mirror of https://github.com/v2ray/v2ray-core
add some logs to tlsping
parent
c5cce8be6f
commit
da8efb4afe
|
@ -2,6 +2,7 @@ package control
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"crypto/x509"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
@ -22,6 +23,15 @@ func (c *TlsPingCommand) Description() Description {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printCertificates(certs []*x509.Certificate) {
|
||||||
|
for _, cert := range certs {
|
||||||
|
if len(cert.DNSNames) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Println("Allowed domains: ", cert.DNSNames)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *TlsPingCommand) Execute(args []string) error {
|
func (c *TlsPingCommand) Execute(args []string) error {
|
||||||
fs := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
fs := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
||||||
ipStr := fs.String("ip", "", "IP address of the domain")
|
ipStr := fs.String("ip", "", "IP address of the domain")
|
||||||
|
@ -53,6 +63,7 @@ func (c *TlsPingCommand) Execute(args []string) error {
|
||||||
}
|
}
|
||||||
fmt.Println("Using IP: ", ip.String())
|
fmt.Println("Using IP: ", ip.String())
|
||||||
|
|
||||||
|
fmt.Println("-------------------")
|
||||||
fmt.Println("Pinging without SNI")
|
fmt.Println("Pinging without SNI")
|
||||||
{
|
{
|
||||||
tcpConn, err := net.DialTCP("tcp", nil, &net.TCPAddr{IP: ip, Port: 443})
|
tcpConn, err := net.DialTCP("tcp", nil, &net.TCPAddr{IP: ip, Port: 443})
|
||||||
|
@ -70,10 +81,12 @@ func (c *TlsPingCommand) Execute(args []string) error {
|
||||||
fmt.Println("Handshake failure: ", err)
|
fmt.Println("Handshake failure: ", err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Handshake succeeded")
|
fmt.Println("Handshake succeeded")
|
||||||
|
printCertificates(tlsConn.ConnectionState().PeerCertificates)
|
||||||
}
|
}
|
||||||
tlsConn.Close()
|
tlsConn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("-------------------")
|
||||||
fmt.Println("Pinging with SNI")
|
fmt.Println("Pinging with SNI")
|
||||||
{
|
{
|
||||||
tcpConn, err := net.DialTCP("tcp", nil, &net.TCPAddr{IP: ip, Port: 443})
|
tcpConn, err := net.DialTCP("tcp", nil, &net.TCPAddr{IP: ip, Port: 443})
|
||||||
|
@ -91,6 +104,7 @@ func (c *TlsPingCommand) Execute(args []string) error {
|
||||||
fmt.Println("handshake failure: ", err)
|
fmt.Println("handshake failure: ", err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("handshake succeeded")
|
fmt.Println("handshake succeeded")
|
||||||
|
printCertificates(tlsConn.ConnectionState().PeerCertificates)
|
||||||
}
|
}
|
||||||
tlsConn.Close()
|
tlsConn.Close()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue