-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
showconf.go
46 lines (40 loc) · 1.24 KB
/
showconf.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
package main
import (
"fmt"
"strings"
"golang.zx2c4.com/wireguard/wgctrl"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
func showConfig(opts *cmdOptions) {
if opts.Interface == "--help" || opts.Interface == "" {
showSubCommandUsage("showconf <interface>", opts)
}
client, err := wgctrl.New()
checkError(err)
dev, err := client.Device(opts.Interface)
checkError(err)
fmt.Printf("[Interface]\n")
fmt.Printf("ListenPort = %d\n", dev.ListenPort)
fmt.Printf("PrivateKey = %s\n", dev.PrivateKey.String())
for _, peer := range dev.Peers {
showConfigPeers(peer)
}
}
func showConfigPeers(peer wgtypes.Peer) {
allowdIpStrings := make([]string, 0, len(peer.AllowedIPs))
for _, v := range peer.AllowedIPs {
allowdIpStrings = append(allowdIpStrings, v.String())
}
psk := peer.PresharedKey.String()
ka := peer.PersistentKeepaliveInterval.Seconds()
fmt.Printf("\n[Peer]\n")
fmt.Printf("PublicKey = %s\n", peer.PublicKey.String())
if psk != "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" {
fmt.Printf("PresharedKey = %s\n", peer.PresharedKey.String())
}
fmt.Printf("AllowedIPs = %s\n", strings.Join(allowdIpStrings, ", "))
fmt.Printf("Endpoint = %s\n", peer.Endpoint.String())
if ka > 0 {
fmt.Printf("PersistentKeepalive = %g\n", ka)
}
}