forked from IamQiuTian/cmdscp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
117 lines (106 loc) · 2.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"./conf"
"./ssh"
"fmt"
"log"
"os"
"runtime"
"sync"
"github.com/urfave/cli"
)
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
log.SetFlags(log.Ltime | log.Lshortfile)
}
var (
grep string
cmd string
files string
dst string
pwdfile string
)
func main() {
get_Args()
InfoList := conf.ReadConfig(pwdfile, grep)
wg := sync.WaitGroup{}
wg.Add(len(InfoList))
for _, info := range InfoList {
conn := ssh.InfoSSH{
User: info.User,
Password: info.Password,
Host: info.Host,
Port: info.Port,
}
err := conn.Connect()
if err != nil {
fmt.Printf("\n \033[0;31m ==================== %v ======================= \033[0m\n", info.Host)
fmt.Println(err)
wg.Done()
continue
}
switch {
case cmd != "":
go conn.Cmd(cmd, &wg)
case files != "":
go conn.Scp(files, dst, &wg)
case cmd != "" && files != "":
os.Exit(0)
default:
os.Exit(0)
}
}
defer wg.Wait()
}
func get_Args() {
app := cli.NewApp()
app.Name = "cmdscp"
app.Version = "v0.0.1"
app.Usage = "shell and send file"
app.Writer = os.Stdout
app.ErrWriter = os.Stderr
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "grep,g",
Value: "false",
Usage: "Input ip grep",
Destination: &grep,
},
cli.StringFlag{
Name: "cmd,c",
Value: "",
Usage: "Input command",
Destination: &cmd,
},
cli.StringFlag{
Name: "file,f",
Value: "",
Usage: "Input source file path",
Destination: &files,
},
cli.StringFlag{
Name: "dst,d",
Value: "",
Usage: "Input target file path",
Destination: &dst,
},
cli.StringFlag{
Name: "pwdfile,p",
Value: ".info.json",
Usage: "Input passwd file path",
Destination: &pwdfile,
},
}
app.Action = func(c *cli.Context) {
if c.String("grep") == "false" {
cli.ShowAppHelp(c)
os.Exit(0)
}
_, err := os.Stat(c.String("pwdfile"))
if os.IsNotExist(err) {
fmt.Println("Password file is none!")
os.Exit(0)
}
}
app.Run(os.Args)
}