-
Notifications
You must be signed in to change notification settings - Fork 48
/
main.go
64 lines (55 loc) · 1.19 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
package main
import (
"flag"
"fmt"
"net"
"os"
"github.com/containers/gvisor-tap-vsock/pkg/transport"
"github.com/containers/gvisor-tap-vsock/pkg/types"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
var (
ip string
port int
user string
key string
endpoint string
)
func main() {
version := types.NewVersion("ssh-over-vsock")
version.AddFlag()
flag.StringVar(&ip, "ip", "192.168.127.2", "ip of the host")
flag.IntVar(&port, "port", 22, "port of the host")
flag.StringVar(&user, "user", "", "ssh user")
flag.StringVar(&key, "key", "", "ssh key")
flag.StringVar(&endpoint, "url", "/tmp/network.sock", "url of the daemon")
flag.Parse()
if version.ShowVersion() {
fmt.Println(version.String())
os.Exit(0)
}
if err := run(); err != nil {
logrus.Fatal(err)
}
}
func run() error {
conn, err := net.Dial("unix", endpoint)
if err != nil {
return errors.Wrap(err, "cannot connect to host")
}
defer conn.Close()
if err := transport.Tunnel(conn, ip, port); err != nil {
return err
}
client, err := newClient(conn, user, key)
if err != nil {
return err
}
out, err := client.output("ps")
if err != nil {
return err
}
fmt.Println(out)
return nil
}