Created
November 13, 2021 01:56
-
-
Save rossigee/6ec347d7690e57aabb94ece8445c3d12 to your computer and use it in GitHub Desktop.
OpenVPN AS XMLRPC client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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