summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-07 07:34:12 -0600
committerJeff Carr <[email protected]>2024-01-07 07:34:12 -0600
commit259b4bdb408fd234cf1c76f94463a85d87fdadb6 (patch)
treef246ca7257253f4f5a33c9b339cec6fea984cb16
parent7343cbfa5753d6df2768936744c25e0465552f32 (diff)
finds and reports OS nameserversv0.5.1
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--linuxstatus/linuxloop.go19
-rw-r--r--linuxstatus/net.go5
2 files changed, 24 insertions, 0 deletions
diff --git a/linuxstatus/linuxloop.go b/linuxstatus/linuxloop.go
index 9127206..c791165 100644
--- a/linuxstatus/linuxloop.go
+++ b/linuxstatus/linuxloop.go
@@ -13,6 +13,7 @@ package linuxstatus
import (
"os"
"os/user"
+ "io/ioutil"
"strconv"
"strings"
"sort"
@@ -66,6 +67,24 @@ func linuxLoop() {
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)
fmt.Println("Process with port 53:", processName)
diff --git a/linuxstatus/net.go b/linuxstatus/net.go
index 22c9a4c..cbb7ad5 100644
--- a/linuxstatus/net.go
+++ b/linuxstatus/net.go
@@ -282,3 +282,8 @@ func (ls *LinuxStatus) GetIPv4() []string {
return strings.Split(tmp, "\n")
}
+func (ls *LinuxStatus) GetNameservers() []string {
+ if ! me.Ready() {return nil}
+ tmp := me.resolver.Get()
+ return strings.Split(tmp, "\n")
+}