MCPcopy Create free account
hub / github.com/Driver-C/tryssh / NewSSHCommand

Function NewSSHCommand

cmd/ssh/ssh.go:18–45  ·  view source on GitHub ↗

NewSSHCommand creates and returns the cobra command for SSH connections.

()

Source from the content-addressed store, hash-verified

16
17// NewSSHCommand creates and returns the cobra command for SSH connections.
18func NewSSHCommand() *cobra.Command {
19 cmd := &cobra.Command{
20 Use: "ssh <ipAddress>",
21 Args: cobra.ExactArgs(1),
22 Short: "Connect to the server through SSH protocol",
23 Long: "Connect to the server through SSH protocol",
24 Run: func(cmd *cobra.Command, args []string) {
25 user, _ := cmd.Flags().GetString("user")
26 concurrencyOpt, _ := cmd.Flags().GetInt("concurrency")
27 timeout, _ := cmd.Flags().GetDuration("timeout")
28 targetIP := args[0]
29 configuration, err := config.LoadConfig()
30 if err != nil {
31 utils.Fatalln(err)
32 }
33 controller := control.NewSSHController(targetIP, configuration)
34 controller.TryLogin(user, concurrencyOpt, timeout)
35 },
36 }
37 cmd.Flags().StringP(
38 "user", "u", "", "Specify a username to attempt to login to the server,\n"+
39 "if the specified username does not exist, try logging in using that username")
40 cmd.Flags().IntP(
41 "concurrency", "c", concurrency, "Number of multiple requests to perform at a time")
42 cmd.Flags().DurationP("timeout", "t", sshTimeout,
43 "SSH timeout when attempting to log in. It can be \"1s\" or \"1m\" or other duration")
44 return cmd
45}

Calls 4

TryLoginMethod · 0.95
LoadConfigFunction · 0.92
FatallnFunction · 0.92
NewSSHControllerFunction · 0.92