Now I added the source for the go plugin as well as Unbound

This commit is contained in:
Victor Robellini 2020-04-02 21:30:44 -04:00
parent 29da2ac0ac
commit fd769e619d
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,51 @@
package main
import (
"fmt"
"net"
"strings"
)
func main() {
//----------------------
// Get the local machine IP address
// https://www.socketloop.com/tutorials/golang-how-do-I-get-the-local-ip-non-loopback-address
//----------------------
var currentIP, currentNetworkHardwareName string
// get all the system's or local machine's network interfaces
interfaces, _ := net.Interfaces()
for _, interf := range interfaces {
if addrs, err := interf.Addrs(); err == nil {
for _, addr := range addrs {
// check the address type and if it is not a loopback the display it
// = GET LOCAL IP ADDRESS
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
currentIP = ipnet.IP.String()
// only interested in the name with current IP address`
if strings.Contains(addr.String(), currentIP) {
currentNetworkHardwareName = interf.Name
}
macAddress := interf.HardwareAddr
hwAddr, err := net.ParseMAC(macAddress.String())
if err != nil {
continue
}
currentNetworkHardwareName = strings.Replace(currentNetworkHardwareName, " ", "", -1)
fmt.Printf("interface,name=%s,ip_address=%s,mac_address=%s status=1\n",
currentNetworkHardwareName, currentIP, hwAddr)
}
}
}
}
}
}

View File

@ -0,0 +1,2 @@
#!/bin/sh
/usr/local/sbin/unbound-control -c /var/unbound/unbound.conf $* | grep -vE 'thread[0-9]+'