finds and reports OS nameservers
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
7343cbfa57
commit
259b4bdb40
|
@ -13,6 +13,7 @@ package linuxstatus
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"io/ioutil"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -66,6 +67,24 @@ func linuxLoop() {
|
||||||
me.uid.Set(tmp)
|
me.uid.Set(tmp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content, _ := ioutil.ReadFile("/etc/resolv.conf")
|
||||||
|
var ns []string
|
||||||
|
for _, line := range strings.Split(string(content), "\n") {
|
||||||
|
parts := strings.Split(line, " ")
|
||||||
|
if len(parts) > 1 {
|
||||||
|
if parts[0] == "nameserver" {
|
||||||
|
ns = append(ns, parts[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(ns)
|
||||||
|
newNS := strings.Join(ns, "\n")
|
||||||
|
if newNS != me.resolver.Get() {
|
||||||
|
log.Log(CHANGE, "resolver changed in /etc/resolv.conf to", ns)
|
||||||
|
me.changed = true
|
||||||
|
me.resolver.Set(newNS)
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
processName := getProcessNameByPort(53)
|
processName := getProcessNameByPort(53)
|
||||||
fmt.Println("Process with port 53:", processName)
|
fmt.Println("Process with port 53:", processName)
|
||||||
|
|
|
@ -282,3 +282,8 @@ func (ls *LinuxStatus) GetIPv4() []string {
|
||||||
return strings.Split(tmp, "\n")
|
return strings.Split(tmp, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ls *LinuxStatus) GetNameservers() []string {
|
||||||
|
if ! me.Ready() {return nil}
|
||||||
|
tmp := me.resolver.Get()
|
||||||
|
return strings.Split(tmp, "\n")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue