Set up wgctrl library Simple create device and if it exists list the number of clients
21 lines
307 B
Go
21 lines
307 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"golang.zx2c4.com/wireguard/wgctrl"
|
|
)
|
|
|
|
func main() {
|
|
client, _ := wgctrl.New()
|
|
defer client.Close()
|
|
|
|
dev, err := client.Device("wg0")
|
|
if err != nil {
|
|
log.Fatalf("get device error: %v", err)
|
|
}
|
|
|
|
fmt.Printf("Device %s has %d peers\n", dev.Name, len(dev.Peers))
|
|
}
|