Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.01 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "bufio"
  5.     "fmt"
  6.     "golang.org/x/crypto/ssh"
  7.     "os"
  8. )
  9.  
  10. var (
  11.     user = "lab_04_2018"
  12.     password = "XBsdhd63sSD"
  13.     host = "lab.posevin.com:22"
  14. )
  15.  
  16. //var (
  17. //  user = "lab_15_2018"
  18. //  password = "SDJDFJFiud3"
  19. //  host = "localhost:2015"
  20. //)
  21.  
  22. func connectToHost() (*ssh.Client, error) {
  23.     sshConfig := &ssh.ClientConfig{
  24.         User: user,
  25.         Auth: []ssh.AuthMethod{ssh.Password(password)},
  26.         HostKeyCallback: ssh.InsecureIgnoreHostKey(),
  27.     }
  28.  
  29.     client, err := ssh.Dial("tcp", host, sshConfig)
  30.     if err != nil {
  31.         return nil, err
  32.     }
  33.     return client, nil
  34. }
  35.  
  36.  
  37. func main() {
  38.     client, err := connectToHost()
  39.     if err != nil {
  40.         panic(err)
  41.     }
  42.     defer client.Close()
  43.  
  44.     reader := bufio.NewReader(os.Stdin)
  45.     for {
  46.         session, err := client.NewSession()
  47.         if err != nil {
  48.             panic(err)
  49.         }
  50.         defer session.Close()
  51.         cmd, _ := reader.ReadString('\n')
  52.         if cmd == "exit\n" {
  53.             break
  54.         }
  55.         out, err := session.Output(cmd)
  56.         if err != nil {
  57.             panic(err)
  58.         }
  59.         fmt.Print(string(out))
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement