-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvbox-client.go
44 lines (37 loc) · 846 Bytes
/
vbox-client.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
package main
import (
"fmt"
"net"
"os"
"strings"
)
func main() {
// Check if any command is passed
if len(os.Args) < 2 {
fmt.Println("Usage: client <vboxmanage commands>")
return
}
// Join the arguments to form the command
command := strings.Join(os.Args[1:], " ")
// Connect to the Unix socket
conn, err := net.Dial("unix", "/opt/vbox/vbox.sock")
if err != nil {
fmt.Println("Error connecting:", err.Error())
return
}
defer conn.Close()
// Send command to the server
_, err = conn.Write([]byte(command + "\n"))
if err != nil {
fmt.Println("Error sending command:", err.Error())
return
}
// Receive the response
response := make([]byte, 4096) // buffer size
n, err := conn.Read(response)
if err != nil {
fmt.Println("Error reading response:", err.Error())
return
}
fmt.Print(string(response[:n]))
}