mirror of
https://github.com/XTLS/RealiTLScanner.git
synced 2026-10-05 05:27:57 +03:00
Refactor print
This commit is contained in:
@@ -9,9 +9,9 @@ Usage
|
|||||||
|
|
||||||
Recommend to run this tool locally. It may cause VPS to be flagged if you run scanner in the cloud.
|
Recommend to run this tool locally. It may cause VPS to be flagged if you run scanner in the cloud.
|
||||||
```
|
```
|
||||||
./RealiTLScanner -addr www.microsoft.com
|
./RealiTLScanner -addr www.microsoft.com -showFail -o
|
||||||
./RealiTLScanner -addr 20.53.203.50
|
./RealiTLScanner -addr 20.53.203.50 -showFail -o
|
||||||
./RealiTLScanner -addr 2607:f8b0:4004:c1b::65 -thread 10
|
./RealiTLScanner -addr 2607:f8b0:4004:c1b::65 -thread 10 -showFail -o
|
||||||
```
|
```
|
||||||
|
|
||||||
Example
|
Example
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ func main() {
|
|||||||
timeOutPtr := flag.Int("timeOut", 10, "Time out of a scan")
|
timeOutPtr := flag.Int("timeOut", 10, "Time out of a scan")
|
||||||
showFailPtr := flag.Bool("showFail", false, "Is Show fail logs")
|
showFailPtr := flag.Bool("showFail", false, "Is Show fail logs")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
fmt.Println("Reality TLS Scanner running: ", *addrPtr, ":", *portPtr)
|
|
||||||
s := Scanner{
|
s := Scanner{
|
||||||
addr: *addrPtr,
|
addr: *addrPtr,
|
||||||
port: *portPtr,
|
port: *portPtr,
|
||||||
@@ -33,7 +32,7 @@ func main() {
|
|||||||
s.logFile, _ = os.OpenFile("results.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
|
s.logFile, _ = os.OpenFile("results.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
|
||||||
}
|
}
|
||||||
location, _ := time.LoadLocation("Asia/Shanghai")
|
location, _ := time.LoadLocation("Asia/Shanghai")
|
||||||
s.logFile.WriteString("start scan at : " + time.Now().In(location).String() + "\n")
|
s.Print(fmt.Sprint("Reality TLS Scanner running: ", *addrPtr, ":", *portPtr, " start scan at : ", time.Now().In(location).String()))
|
||||||
defer s.logFile.Close()
|
defer s.logFile.Close()
|
||||||
s.Run()
|
s.Run()
|
||||||
}
|
}
|
||||||
@@ -59,7 +58,7 @@ func (s *Scanner) Run() {
|
|||||||
}
|
}
|
||||||
conn, err := net.DialTimeout("tcp", str+":"+s.port, s.timeout)
|
conn, err := net.DialTimeout("tcp", str+":"+s.port, s.timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Dial failed: ", err)
|
s.Print(fmt.Sprint("Dial failed: ", err))
|
||||||
} else {
|
} else {
|
||||||
addr = conn.RemoteAddr().(*net.TCPAddr).IP
|
addr = conn.RemoteAddr().(*net.TCPAddr).IP
|
||||||
line := "" + conn.RemoteAddr().String() + " \t"
|
line := "" + conn.RemoteAddr().String() + " \t"
|
||||||
@@ -70,19 +69,19 @@ func (s *Scanner) Run() {
|
|||||||
})
|
})
|
||||||
err = c.Handshake()
|
err = c.Handshake()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("", line, "TLS handshake failed: ", err)
|
s.Print(fmt.Sprint("", line, "TLS handshake failed: ", err))
|
||||||
} else {
|
} else {
|
||||||
state := c.ConnectionState()
|
state := c.ConnectionState()
|
||||||
alpn := state.NegotiatedProtocol
|
alpn := state.NegotiatedProtocol
|
||||||
if alpn == "" {
|
if alpn == "" {
|
||||||
alpn = " "
|
alpn = " "
|
||||||
}
|
}
|
||||||
fmt.Println(fmt.Sprint("", line, "----- Found TLS v", TlsDic[state.Version], "\tALPN ", alpn, "\t", state.PeerCertificates[0].Subject))
|
s.Print(fmt.Sprint("", line, "----- Found TLS v", TlsDic[state.Version], "\tALPN ", alpn, "\t", state.PeerCertificates[0].Subject))
|
||||||
c.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if addr == nil {
|
if addr == nil {
|
||||||
fmt.Println("Invalid address format")
|
s.Print("Invalid address format")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +114,9 @@ func (s *Scanner) Scan(increment bool) {
|
|||||||
}
|
}
|
||||||
conn, err := net.DialTimeout("tcp", str+":"+s.port, s.timeout)
|
conn, err := net.DialTimeout("tcp", str+":"+s.port, s.timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Dial failed: ", err)
|
if s.showFail {
|
||||||
|
s.Print(fmt.Sprint("Dial failed: ", err))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
line := "" + conn.RemoteAddr().String() + " \t"
|
line := "" + conn.RemoteAddr().String() + " \t"
|
||||||
conn.SetDeadline(time.Now().Add(s.timeout))
|
conn.SetDeadline(time.Now().Add(s.timeout))
|
||||||
@@ -126,7 +127,7 @@ func (s *Scanner) Scan(increment bool) {
|
|||||||
err = c.Handshake()
|
err = c.Handshake()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if s.showFail {
|
if s.showFail {
|
||||||
fmt.Println("", line, "TLS handshake failed: ", err)
|
s.Print(fmt.Sprint("", line, "TLS handshake failed: ", err))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
@@ -135,18 +136,21 @@ func (s *Scanner) Scan(increment bool) {
|
|||||||
if alpn == "" {
|
if alpn == "" {
|
||||||
alpn = " "
|
alpn = " "
|
||||||
}
|
}
|
||||||
outStr := fmt.Sprint("", line, "----- Found TLS v", TlsDic[state.Version], "\tALPN ", alpn, "\t", state.PeerCertificates[0].Subject)
|
if s.showFail || (state.Version == 0x0304 && alpn == "h2") {
|
||||||
if state.Version == 0x0304 && alpn == "h2" {
|
s.Print(fmt.Sprint("", line, "----- Found TLS v", TlsDic[state.Version], "\tALPN ", alpn, "\t", state.PeerCertificates[0].Subject))
|
||||||
if s.output {
|
|
||||||
s.logFile.WriteString(outStr + "\n")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fmt.Println(outStr)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
go s.Scan(increment)
|
go s.Scan(increment)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Scanner) Print(outStr string) {
|
||||||
|
if s.output {
|
||||||
|
s.logFile.WriteString(outStr + "\n")
|
||||||
|
}
|
||||||
|
fmt.Println(outStr)
|
||||||
|
}
|
||||||
|
|
||||||
func nextIP(ip net.IP, increment bool) net.IP {
|
func nextIP(ip net.IP, increment bool) net.IP {
|
||||||
// Convert to big.Int and increment
|
// Convert to big.Int and increment
|
||||||
ipb := big.NewInt(0).SetBytes([]byte(ip))
|
ipb := big.NewInt(0).SetBytes([]byte(ip))
|
||||||
|
|||||||
Reference in New Issue
Block a user