@@ -3,50 +3,18 @@ package main
33import (
44 "crypto/tls"
55 "log/slog"
6- "math/big"
76 "net"
87 "strconv"
98 "strings"
10- "sync"
119 "time"
1210)
1311
14- type Scanner struct {
15- mu * sync.Mutex
16- high net.IP
17- low net.IP
18- }
19-
20- func (s * Scanner ) Scan (host Host , out chan <- string , increment bool ) Host {
21- if host .Infinity && host .IP != nil {
22- s .mu .Lock ()
23- if s .high == nil {
24- s .high = host .IP
25- s .low = host .IP
26- host .Origin = ""
27- host .Type = HostTypeIP
28- } else if increment {
29- s .high = nextIP (s .high , increment )
30- host .IP = s .high
31- } else {
32- s .low = nextIP (s .low , increment )
33- host .IP = s .low
34- }
35- s .mu .Unlock ()
36- }
37- host = ScanTLS (host , out , increment )
38- if host .Infinity && host .IP != nil {
39- go s .Scan (host , out , increment )
40- }
41- return host
42- }
43-
44- func ScanTLS (host Host , out chan <- string , increment bool ) Host {
12+ func ScanTLS (host Host , out chan <- string ) {
4513 if host .IP == nil {
4614 ips , err := net .LookupIP (host .Origin )
4715 if err != nil {
4816 slog .Debug ("Failed to lookup" , "origin" , host .Origin , "err" , err )
49- return host
17+ return
5018 }
5119 var arr []net.IP
5220 for _ , ip := range ips {
@@ -56,21 +24,21 @@ func ScanTLS(host Host, out chan<- string, increment bool) Host {
5624 }
5725 if len (arr ) == 0 {
5826 slog .Debug ("No IP found" , "origin" , host .Origin )
59- return host
27+ return
6028 }
6129 host .IP = arr [0 ]
6230 }
6331 hostPort := net .JoinHostPort (host .IP .String (), strconv .Itoa (port ))
6432 conn , err := net .DialTimeout ("tcp" , hostPort , time .Duration (timeout )* time .Second )
6533 if err != nil {
6634 slog .Debug ("Cannot dial" , "target" , hostPort )
67- return host
35+ return
6836 }
6937 defer conn .Close ()
7038 err = conn .SetDeadline (time .Now ().Add (time .Duration (timeout ) * time .Second ))
7139 if err != nil {
7240 slog .Error ("Error setting deadline" , "err" , err )
73- return host
41+ return
7442 }
7543 tlsCfg := & tls.Config {
7644 InsecureSkipVerify : true ,
@@ -84,7 +52,7 @@ func ScanTLS(host Host, out chan<- string, increment bool) Host {
8452 err = c .Handshake ()
8553 if err != nil {
8654 slog .Debug ("TLS handshake failed" , "target" , hostPort )
87- return host
55+ return
8856 }
8957 state := c .ConnectionState ()
9058 alpn := state .NegotiatedProtocol
@@ -102,20 +70,4 @@ func ScanTLS(host Host, out chan<- string, increment bool) Host {
10270 log ("Connected to target" , "feasible" , feasible , "ip" , host .IP .String (),
10371 "origin" , host .Origin ,
10472 "tls" , tls .VersionName (state .Version ), "alpn" , alpn , "cert-domain" , domain , "cert-issuer" , issuers )
105- return host
106- }
107-
108- func nextIP (ip net.IP , increment bool ) net.IP {
109- // Convert to big.Int and increment
110- ipb := big .NewInt (0 ).SetBytes ([]byte (ip ))
111- if increment {
112- ipb .Add (ipb , big .NewInt (1 ))
113- } else {
114- ipb .Sub (ipb , big .NewInt (1 ))
115- }
116-
117- // Add leading zeros
118- b := ipb .Bytes ()
119- b = append (make ([]byte , len (ip )- len (b )), b ... )
120- return net .IP (b )
12173}
0 commit comments