Skip to content

Instantly share code, notes, and snippets.

@rossigee
Created November 13, 2021 01:56
Show Gist options
  • Save rossigee/6ec347d7690e57aabb94ece8445c3d12 to your computer and use it in GitHub Desktop.
Save rossigee/6ec347d7690e57aabb94ece8445c3d12 to your computer and use it in GitHub Desktop.
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