@@ -27,33 +27,39 @@ import (
2727
2828const OUTPUT_IP_PER_LINE = 3
2929
30- func CheckIP (subnet string , isVerbose bool ) {
30+ func CheckIP (subnets , excludes [] string , isVerbose bool ) {
3131 checkerGroup := & sync.WaitGroup {}
3232 t := time .Now ()
33- hosts , _ := GetAllIPsFromCIDR (subnet )
34- for index := range hosts {
35- //time.Sleep(500)
33+
34+ var allHosts []HostInfo
35+ for _ , subnet := range subnets {
36+ hosts , _ := GetAllIPsFromCIDR (subnet , excludes )
37+ allHosts = append (allHosts , hosts ... )
38+ }
39+
40+ for index := range allHosts {
3641 checkerGroup .Add (1 )
3742
3843 go func (index int ) {
3944 defer checkerGroup .Done ()
40- hosts [index ].isUsed = Ping (hosts [index ].host )
45+ allHosts [index ].isUsed = Ping (allHosts [index ].host )
4146 if isVerbose {
42- if hosts [index ].isUsed {
43- fmt .Println ("已使用IP:" , hosts [index ].host .String ())
47+ if allHosts [index ].isUsed {
48+ fmt .Println ("已使用IP:" , allHosts [index ].host .String ())
4449 } else {
45- fmt .Println ("未使用IP:" , hosts [index ].host .String ())
50+ fmt .Println ("未使用IP:" , allHosts [index ].host .String ())
4651 }
4752 }
4853 }(index )
4954 }
55+
5056 checkerGroup .Wait ()
5157 elapsed := time .Since (t )
5258 _ , _ = fmt .Fprintln (os .Stderr , "IP扫描完成,耗时" , elapsed )
5359 fmt .Println ("已使用IP:" )
54- printIPList (hosts , true )
60+ printIPList (allHosts , true )
5561 fmt .Println ("未使用IP:" )
56- printIPList (hosts , false )
62+ printIPList (allHosts , false )
5763}
5864
5965func printIPList (hosts []HostInfo , boolFilter bool ) {
0 commit comments