Skip to content

Instantly share code, notes, and snippets.

@rossigee
Created Nov 13, 2021
Embed
What would you like to do?
OpenVPN AS XMLRPC client
package main
import (
"fmt"
"net"
"net/http"
"alexejk.io/go-xmlrpc"
)
func main() {
dialer := func(_, _ string) (net.Conn, error) {
return net.Dial("unix", "/usr/local/openvpn_as/etc/sock/sagent.localroot")
}
httpc := http.Client{
Transport: &http.Transport{
Dial: dialer,
},
}
opts := []xmlrpc.Option{xmlrpc.HttpClient(&httpc)}
client, _ := xmlrpc.NewClient("http://localhost/", opts...)
result := &struct {
NClients struct {
NClients int
}
}{}
err := client.Call("GetVPNSummary", nil, result)
if err != nil {
fmt.Printf("Error: %s\n", err)
} else {
fmt.Printf("Connected clients: %d\n", result.NClients.NClients)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment