From 378c12a285465dfacff0aaca22fc28d4ff8cc5c0 Mon Sep 17 00:00:00 2001 From: Feng_Qi Date: Sat, 20 Jan 2018 10:53:42 +0800 Subject: [PATCH] 0.2.1-version --- g/cfg.go | 16 +++++++++++++++- g/const.go | 3 ++- main.go | 15 ++++++++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/g/cfg.go b/g/cfg.go index 2a9ed96..0c98fc1 100644 --- a/g/cfg.go +++ b/g/cfg.go @@ -100,7 +100,21 @@ func WriteIntoTxt(sshResult SSHResult) error { return nil } -func GetIpList(filePath string) ([]string, error) { +func GetIpList(ipString string) ([]string, error) { + res := SplitString(ipString) + var allIp []string + if len(res) > 0 { + for _, sip := range res { + aip := ParseIp(sip) + for _, ip := range aip { + allIp = append(allIp, ip) + } + } + } + return allIp, nil +} + +func GetIpListFromFile(filePath string) ([]string, error) { res, err := Getfile(filePath) if err != nil { return nil, nil diff --git a/g/const.go b/g/const.go index ecbb867..71090c5 100644 --- a/g/const.go +++ b/g/const.go @@ -4,6 +4,7 @@ package g // 0.1 fisrt version // 0.1.2 fix ssh error on h3c switch // 0.2 +// 0.2.1 const ( - VERSION = "0.2" + VERSION = "0.2.1" ) diff --git a/main.go b/main.go index 4a16c95..50982ec 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( func main() { version := flag.Bool("v", false, "show version") hosts := flag.String("hosts", "", "host address list") + ips := flag.String("ips", "", "ip address list") cmds := flag.String("cmds", "", "cmds") username := flag.String("u", "", "username") password := flag.String("p", "", "password") @@ -24,7 +25,7 @@ func main() { ciphers := flag.String("ciphers", "", "ciphers") cmdFile := flag.String("cmdfile", "", "cmdfile path") hostFile := flag.String("hostfile", "", "hostfile path") - ipFile := flag.String("ipfile", "", "hostfile path") + ipFile := flag.String("ipfile", "", "ipfile path") cfgFile := flag.String("c", "", "cfg File Path") jsonMode := flag.Bool("j", false, "print output in json format") outTxt := flag.Bool("outTxt", false, "write result into txt") @@ -46,9 +47,9 @@ func main() { } if *ipFile != "" { - hostList, err = g.GetIpList(*ipFile) + hostList, err = g.GetIpListFromFile(*ipFile) if err != nil { - log.Println("load hostlist error: ", err) + log.Println("load iplist error: ", err) return } } @@ -60,6 +61,14 @@ func main() { return } } + if *ips != "" { + hostList, err = g.GetIpList(*ips) + if err != nil { + log.Println("load iplist error: ", err) + return + } + } + if *hosts != "" { hostList = g.SplitString(*hosts) }