mirror of
https://github.com/shanghai-edu/multissh.git
synced 2025-12-16 21:37:50 +00:00
完成读取json文件、结果导出为txt文件、超时处理(时限参数可输入) 控制并发访问
This commit is contained in:
parent
9e410eaa21
commit
47366d7696
3 changed files with 141 additions and 45 deletions
32
cfg.go
32
cfg.go
|
|
@ -1,10 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
|
@ -36,6 +39,35 @@ func Getfile(filePath string) ([]string, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
//gu
|
||||
func GetJsonFile(filePath string) ([]SSHHost, error) {
|
||||
result := []SSHHost{}
|
||||
b, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
log.Println("read file ", filePath, err)
|
||||
return result, err
|
||||
}
|
||||
var m HostJson
|
||||
json.Unmarshal(b, &m)
|
||||
result = m.SshHosts
|
||||
return result, nil
|
||||
}
|
||||
func WriteIntoTxt(sshHost SSHHost) error {
|
||||
outputFile, outputError := os.OpenFile(sshHost.Host+".txt", os.O_WRONLY|os.O_CREATE, 0666)
|
||||
if outputError != nil {
|
||||
return outputError
|
||||
}
|
||||
defer outputFile.Close()
|
||||
|
||||
outputWriter := bufio.NewWriter(outputFile)
|
||||
//var outputString string
|
||||
|
||||
outputString := sshHost.Result
|
||||
outputWriter.WriteString(outputString)
|
||||
outputWriter.Flush()
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetIpList(filePath string) ([]string, error) {
|
||||
res, err := Getfile(filePath)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue