@@ -31,14 +31,18 @@ func main() {
3131 flag .StringVar (& in , "in" , "" , "Specify a file that contains multiple " +
3232 "IPs, IP CIDRs or domains to scan, divided by line break" )
3333 flag .IntVar (& port , "port" , 443 , "Specify a HTTPS port to check" )
34- flag .IntVar (& thread , "thread" , 1 , "Count of concurrent tasks" )
34+ flag .IntVar (& thread , "thread" , 2 , "Count of concurrent tasks" )
3535 flag .StringVar (& out , "out" , "out.csv" , "Output file to store the result" )
3636 flag .IntVar (& timeout , "timeout" , 10 , "Timeout for every check" )
3737 flag .BoolVar (& verbose , "v" , false , "Verbose output" )
3838 flag .BoolVar (& enableIPv6 , "46" , false , "Enable IPv6 in additional to IPv4" )
3939 flag .StringVar (& url , "url" , "" , "Crawl the domain list from a URL, " +
4040 "e.g. https://launchpad.net/ubuntu/+archivemirrors" )
4141 flag .Parse ()
42+ s := Scanner {
43+ mu : new (sync.Mutex ),
44+ }
45+
4246 if verbose {
4347 slog .SetDefault (slog .New (slog .NewTextHandler (os .Stdout , & slog.HandlerOptions {
4448 Level : slog .LevelDebug ,
@@ -66,15 +70,15 @@ func main() {
6670 }
6771 var hostChan <- chan Host
6872 if addr != "" {
69- hostChan = Iterate (strings .NewReader (addr ))
73+ hostChan = Iterate (strings .NewReader (addr ), true )
7074 } else if in != "" {
7175 f , err := os .Open (in )
7276 if err != nil {
7377 slog .Error ("Error reading file" , "path" , in )
7478 return
7579 }
7680 defer f .Close ()
77- hostChan = Iterate (f )
81+ hostChan = Iterate (f , false )
7882 } else {
7983 slog .Info ("Fetching url..." )
8084 resp , err := http .Get (url )
@@ -95,7 +99,7 @@ func main() {
9599 }
96100 domains = RemoveDuplicateStr (domains )
97101 slog .Info ("Parsed domains" , "count" , len (domains ))
98- hostChan = Iterate (strings .NewReader (strings .Join (domains , "\n " )))
102+ hostChan = Iterate (strings .NewReader (strings .Join (domains , "\n " )), len ( domains ) <= 1 )
99103 }
100104 outCh := OutWriter (outWriter )
101105 defer close (outCh )
@@ -104,7 +108,13 @@ func main() {
104108 for i := 0 ; i < thread ; i ++ {
105109 go func () {
106110 for ip := range hostChan {
107- ScanTLS (ip , outCh )
111+ s .Scan (ip , outCh , true )
112+ if ip .Infinity { // only one ip
113+ for i := 0 ; i < thread - 1 ; i ++ {
114+ go s .Scan (ip , outCh , i % 2 == 1 )
115+ }
116+ for {}
117+ }
108118 }
109119 wg .Done ()
110120 }()
0 commit comments