@@ -33,33 +33,47 @@ type Scanner struct {
3333 numberOfThread int
3434 mu * sync.Mutex
3535 high net.IP
36- low net.IP
36+ low net.IP
3737}
3838
3939func (s * Scanner ) Run () {
40- conn , err := net .DialTimeout ( "tcp" , s .addr + ":" + s . port , s . timeout )
41- if err ! = nil {
42- fmt .Println ("Dial failed: " , err )
40+ addr := net .ParseIP ( s .addr )
41+ if addr = = nil {
42+ fmt .Println ("Invalid address format" )
4343 return
4444 }
45- line := "" + conn .RemoteAddr ().String () + " \t ----- "
46- s .mu .Lock ()
47- s .high = conn .RemoteAddr ().(* net.TCPAddr ).IP
48- s .low = conn .RemoteAddr ().(* net.TCPAddr ).IP
49- s .mu .Unlock ()
50- conn .SetDeadline (time .Now ().Add (s .timeout ))
51- c := tls .Client (conn , & tls.Config {
52- InsecureSkipVerify : true ,
53- NextProtos : []string {"h2" , "http/1.1" },
54- })
55- err = c .Handshake ()
45+ str := addr .String ()
46+ if addr .To4 () == nil {
47+ str = "[" + str + "]"
48+ }
49+ conn , err := net .DialTimeout ("tcp" , str + ":" + s .port , s .timeout )
5650 if err != nil {
57- fmt .Println ("" , line , "TLS handshake failed: " , err )
51+ fmt .Println ("Dial failed: " , err )
5852 } else {
59- defer c .Close ()
60- state := c .ConnectionState ()
61- fmt .Println ("" , line , "Found TLS v" , TlsDic [state .Version ], "\t ALPN" , state .NegotiatedProtocol , "\t " , state .PeerCertificates [0 ].Subject )
53+ line := "" + conn .RemoteAddr ().String () + " \t "
54+ conn .SetDeadline (time .Now ().Add (s .timeout ))
55+ c := tls .Client (conn , & tls.Config {
56+ InsecureSkipVerify : true ,
57+ NextProtos : []string {"h2" , "http/1.1" },
58+ })
59+ err = c .Handshake ()
60+ if err != nil {
61+ fmt .Println ("" , line , "TLS handshake failed: " , err )
62+ } else {
63+ state := c .ConnectionState ()
64+ alpn := state .NegotiatedProtocol
65+ if alpn == "" {
66+ alpn = " "
67+ }
68+ fmt .Println ("" , line , "----- Found TLS v" , TlsDic [state .Version ], "\t ALPN" , alpn , "\t " , state .PeerCertificates [0 ].Subject )
69+ c .Close ()
70+ }
6271 }
72+
73+ s .mu .Lock ()
74+ s .high = addr
75+ s .low = addr
76+ s .mu .Unlock ()
6377 for i := 0 ; i < s .numberOfThread ; i ++ {
6478 go s .Scan (i % 2 == 0 )
6579 }
@@ -69,21 +83,25 @@ func (s *Scanner) Run() {
6983}
7084
7185func (s * Scanner ) Scan (increment bool ) {
72- var addr string
86+ var addr net. IP
7387 s .mu .Lock ()
7488 if increment {
7589 s .high = nextIP (s .high , increment )
76- addr = s .high . String ()
90+ addr = s .high
7791 } else {
7892 s .low = nextIP (s .low , increment )
79- addr = s .low . String ()
93+ addr = s .low
8094 }
8195 s .mu .Unlock ()
82- conn , err := net .DialTimeout ("tcp" , addr + ":" + s .port , s .timeout )
96+ str := addr .String ()
97+ if addr .To4 () == nil {
98+ str = "[" + str + "]"
99+ }
100+ conn , err := net .DialTimeout ("tcp" , str + ":" + s .port , s .timeout )
83101 if err != nil {
84102 fmt .Println ("Dial failed: " , err )
85103 } else {
86- line := "" + conn .RemoteAddr ().String () + " \t ----- "
104+ line := "" + conn .RemoteAddr ().String () + " \t "
87105 conn .SetDeadline (time .Now ().Add (s .timeout ))
88106 c := tls .Client (conn , & tls.Config {
89107 InsecureSkipVerify : true ,
@@ -95,7 +113,11 @@ func (s *Scanner) Scan(increment bool) {
95113 } else {
96114 defer c .Close ()
97115 state := c .ConnectionState ()
98- fmt .Println ("" , line , "Found TLS v" , TlsDic [state .Version ], "\t ALPN" , state .NegotiatedProtocol , "\t " , state .PeerCertificates [0 ].Subject )
116+ alpn := state .NegotiatedProtocol
117+ if alpn == "" {
118+ alpn = " "
119+ }
120+ fmt .Println ("" , line , "----- Found TLS v" , TlsDic [state .Version ], "\t ALPN" , alpn , "\t " , state .PeerCertificates [0 ].Subject )
99121 }
100122 }
101123 go s .Scan (increment )
0 commit comments