From 963f9e2155f7aeb43cb22a2ad84ad7c62093bd74 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 7 Jan 2024 07:34:12 -0600 Subject: finds and reports OS nameservers Signed-off-by: Jeff Carr --- linuxstatus/linuxloop.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'linuxstatus/linuxloop.go') 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) -- cgit v1.2.3