start dns resolver detection and debugging
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
a417cb2930
commit
9abe9f9947
2
bash.go
2
bash.go
|
@ -54,7 +54,7 @@ func test() error {
|
||||||
|
|
||||||
func mainBash() {
|
func mainBash() {
|
||||||
if err := test(); err != nil {
|
if err := test(); err != nil {
|
||||||
log.Println(logError, "exit in mainBash()")
|
debug(LogError, "exit in mainBash()")
|
||||||
exit(err)
|
exit(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
dns.go
2
dns.go
|
@ -24,7 +24,7 @@ func (h *Host) verifyETC() bool {
|
||||||
func (h *Host) updateIPs(host string) {
|
func (h *Host) updateIPs(host string) {
|
||||||
ips, err := net.LookupIP(host)
|
ips, err := net.LookupIP(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(logError, "updateIPs failed", err)
|
debug(LogError, "updateIPs failed", err)
|
||||||
}
|
}
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
log.Println(host, ip)
|
log.Println(host, ip)
|
||||||
|
|
|
@ -14,7 +14,7 @@ func watchSysClassNet() {
|
||||||
// Create new watcher.
|
// Create new watcher.
|
||||||
watcher, err := fsnotify.NewWatcher()
|
watcher, err := fsnotify.NewWatcher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(logError, "watchSysClassNet() failed:", err)
|
debug(LogError, "watchSysClassNet() failed:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer watcher.Close()
|
defer watcher.Close()
|
||||||
|
@ -43,7 +43,7 @@ func watchSysClassNet() {
|
||||||
// Add a path.
|
// Add a path.
|
||||||
err = watcher.Add("/tmp")
|
err = watcher.Add("/tmp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(logError, "watchSysClassNet() watcher.Add() failed:", err)
|
debug(LogError, "watchSysClassNet() watcher.Add() failed:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
gui.go
22
gui.go
|
@ -100,6 +100,25 @@ func debugTab(title string) {
|
||||||
dumpIPs("www.apple.com")
|
dumpIPs("www.apple.com")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
g2 = tab.NewGroup("debugging options")
|
||||||
|
|
||||||
|
// DEBUG flags
|
||||||
|
dbOn := g2.NewCheckbox("turn on debugging (will override all flags below)")
|
||||||
|
dbOn.Custom = func() {
|
||||||
|
DEBUGON = dbOn.B
|
||||||
|
}
|
||||||
|
|
||||||
|
dbNet := g2.NewCheckbox("turn on network debugging)")
|
||||||
|
dbNet.Custom = func() {
|
||||||
|
DEBUGNET = dbNet.B
|
||||||
|
}
|
||||||
|
|
||||||
|
dbProc := g2.NewCheckbox("turn on /proc debugging)")
|
||||||
|
dbProc.Custom = func() {
|
||||||
|
DEBUGPROC = dbProc.B
|
||||||
|
}
|
||||||
|
|
||||||
|
// various timeout settings
|
||||||
g2.NewLabel("control panel TTL (in tenths of seconds)")
|
g2.NewLabel("control panel TTL (in tenths of seconds)")
|
||||||
ttl := g2.NewSlider("dnsTTL", 1, 100)
|
ttl := g2.NewSlider("dnsTTL", 1, 100)
|
||||||
ttl.Set(me.dnsTTL * 10)
|
ttl.Set(me.dnsTTL * 10)
|
||||||
|
@ -115,6 +134,9 @@ func debugTab(title string) {
|
||||||
me.dnsTTLsleep = float64(ttl2.I) / 10
|
me.dnsTTLsleep = float64(ttl2.I) / 10
|
||||||
log.Println("dnsTTLsleep =", me.dnsTTLsleep)
|
log.Println("dnsTTLsleep =", me.dnsTTLsleep)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g2.Margin()
|
||||||
|
g2.Pad()
|
||||||
}
|
}
|
||||||
|
|
||||||
func myDefaultExit(n *gui.Node) {
|
func myDefaultExit(n *gui.Node) {
|
||||||
|
|
14
log.go
14
log.go
|
@ -8,12 +8,12 @@ import (
|
||||||
|
|
||||||
// various debugging flags
|
// various debugging flags
|
||||||
var logNow bool = true // useful for active development
|
var logNow bool = true // useful for active development
|
||||||
var logError bool = true
|
var LogError bool = true
|
||||||
var logWarn bool = false
|
var LogProc bool = false // turn on /proc debugging output
|
||||||
var logInfo bool = false
|
|
||||||
var logVerbose bool = false
|
|
||||||
|
|
||||||
var DEBUGOFF bool = true
|
var DEBUGON bool = false
|
||||||
|
var DEBUGPROC bool = false
|
||||||
|
var DEBUGNET bool = false
|
||||||
|
|
||||||
var SPEW witlog.Spewt
|
var SPEW witlog.Spewt
|
||||||
|
|
||||||
|
@ -31,12 +31,12 @@ func sleep(a ...any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func exit(a ...any) {
|
func exit(a ...any) {
|
||||||
log.Println(logError, "got to log() exit")
|
debug(LogError, "got to log() exit")
|
||||||
witlog.Exit(a...)
|
witlog.Exit(a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func debug(a ...any) {
|
func debug(a ...any) {
|
||||||
if (DEBUGOFF) {
|
if (! DEBUGON) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
main.go
13
main.go
|
@ -107,9 +107,20 @@ func dnsTTL() {
|
||||||
|
|
||||||
if (me.changed) {
|
if (me.changed) {
|
||||||
stamp := time.Now().Format("2006/01/02 15:04:05")
|
stamp := time.Now().Format("2006/01/02 15:04:05")
|
||||||
log.Println(logError, "Network things changed on", stamp)
|
debug(LogError, "Network things changed on", stamp)
|
||||||
updateDNS()
|
updateDNS()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processName := getProcessNameByPort(53)
|
||||||
|
fmt.Println("Process with port 53:", processName)
|
||||||
|
/*
|
||||||
|
commPath := filepath.Join("/proc", proc.Name(), "comm")
|
||||||
|
comm, err := ioutil.ReadFile(commPath)
|
||||||
|
if err != nil {
|
||||||
|
return "", err // Error reading the process name
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(string(comm)), nil
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
4
net.go
4
net.go
|
@ -7,8 +7,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var DEBUGNET bool = false
|
|
||||||
|
|
||||||
// this doesn't work
|
// this doesn't work
|
||||||
/*
|
/*
|
||||||
func watchNetworkInterfaces() {
|
func watchNetworkInterfaces() {
|
||||||
|
@ -187,6 +185,7 @@ func checkIP(ip *net.IPNet, i net.Interface) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func scanInterfaces() {
|
func scanInterfaces() {
|
||||||
|
debug(DEBUGNET, "scanInterfaces() START")
|
||||||
me.changed = false
|
me.changed = false
|
||||||
ifaces, _ := net.Interfaces()
|
ifaces, _ := net.Interfaces()
|
||||||
// me.ifnew = ifaces
|
// me.ifnew = ifaces
|
||||||
|
@ -230,6 +229,7 @@ func scanInterfaces() {
|
||||||
all6 = strings.TrimSpace(all6)
|
all6 = strings.TrimSpace(all6)
|
||||||
me.IPv4.SetText(all4)
|
me.IPv4.SetText(all4)
|
||||||
me.IPv6.SetText(all6)
|
me.IPv6.SetText(all6)
|
||||||
|
debug(DEBUGNET, "scanInterfaces() END")
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete network interfaces and ip addresses from the gui
|
// delete network interfaces and ip addresses from the gui
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getProcessNameByPort(port int) string {
|
||||||
|
// Convert port to hex string
|
||||||
|
portHex := strconv.FormatInt(int64(port), 16)
|
||||||
|
|
||||||
|
// Function to search /proc/net/tcp or /proc/net/udp
|
||||||
|
searchProcNet := func(file string) string {
|
||||||
|
data, err := ioutil.ReadFile(file)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
// debug(DEBUGPROC, "searchProcNet() data:", string(data))
|
||||||
|
|
||||||
|
lines := strings.Split(string(data), "\n")
|
||||||
|
for _, line := range lines {
|
||||||
|
fields := strings.Fields(line)
|
||||||
|
debug(DEBUGPROC, "searchProcNet() portHex:", portHex)
|
||||||
|
if (len(fields) > 9) {
|
||||||
|
debug(DEBUGPROC, "searchProcNet() fields[9]", fields[9])
|
||||||
|
}
|
||||||
|
debug(DEBUGPROC, "searchProcNet() lines:", line)
|
||||||
|
if len(fields) > 1 {
|
||||||
|
parts := strings.Split(fields[1], ":")
|
||||||
|
if len(parts) > 1 {
|
||||||
|
// Convert the hexadecimal string to an integer
|
||||||
|
value, _ := strconv.ParseInt(parts[1], 16, 64)
|
||||||
|
debug(DEBUGPROC, "searchProcNet() value, port =", value, port, "parts[1] =", parts[1])
|
||||||
|
if (port == int(value)) {
|
||||||
|
debug(DEBUGPROC, "searchProcNet() THIS IS THE LINE:", fields)
|
||||||
|
return fields[9]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search TCP and then UDP
|
||||||
|
inode := searchProcNet("/proc/net/tcp")
|
||||||
|
if inode == "" {
|
||||||
|
inode = searchProcNet("/proc/net/udp")
|
||||||
|
}
|
||||||
|
debug(DEBUGPROC, "searchProcNet() inode =", inode)
|
||||||
|
|
||||||
|
// Search for process with the inode
|
||||||
|
procs, _ := ioutil.ReadDir("/proc")
|
||||||
|
for _, proc := range procs {
|
||||||
|
if !proc.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fdPath := filepath.Join("/proc", proc.Name(), "fd")
|
||||||
|
fds, err := ioutil.ReadDir(fdPath)
|
||||||
|
if err != nil {
|
||||||
|
continue // Process might have exited; skip it
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, fd := range fds {
|
||||||
|
fdLink, _ := os.Readlink(filepath.Join(fdPath, fd.Name()))
|
||||||
|
var s string
|
||||||
|
s = "socket:["+inode+"]"
|
||||||
|
if strings.Contains(fdLink, "socket:[") {
|
||||||
|
debug(DEBUGPROC, "searchProcNet() fdLink has socket:", fdLink)
|
||||||
|
debug(DEBUGPROC, "searchProcNet() proc.Name() =", proc.Name(), "s =", s)
|
||||||
|
}
|
||||||
|
if strings.Contains(fdLink, "socket:[35452]") {
|
||||||
|
debug(DEBUGPROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
|
||||||
|
return proc.Name()
|
||||||
|
}
|
||||||
|
if strings.Contains(fdLink, "socket:[35450]") {
|
||||||
|
debug(DEBUGPROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
|
||||||
|
return proc.Name()
|
||||||
|
}
|
||||||
|
if strings.Contains(fdLink, "socket:[35440]") {
|
||||||
|
debug(DEBUGPROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
|
||||||
|
return proc.Name()
|
||||||
|
}
|
||||||
|
if strings.Contains(fdLink, "socket:[21303]") {
|
||||||
|
debug(DEBUGPROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
|
||||||
|
// return proc.Name()
|
||||||
|
}
|
||||||
|
if strings.Contains(fdLink, "socket:["+inode+"]") {
|
||||||
|
return proc.Name()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
|
@ -10,7 +10,7 @@ func Example_listLink() {
|
||||||
// Dial a connection to the rtnetlink socket
|
// Dial a connection to the rtnetlink socket
|
||||||
conn, err := rtnetlink.Dial(nil)
|
conn, err := rtnetlink.Dial(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(logError, "Example_listLink() failed", err)
|
debug(LogError, "Example_listLink() failed", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
4
unix.go
4
unix.go
|
@ -23,7 +23,7 @@ func Escalate() {
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(logError, "exit in Escalate()")
|
debug(LogError, "exit in Escalate()")
|
||||||
exit(err)
|
exit(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func DumpPublicDNSZone(zone string) {
|
||||||
func dumpIPs(host string) {
|
func dumpIPs(host string) {
|
||||||
ips, err := net.LookupIP(host)
|
ips, err := net.LookupIP(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(logError, "dumpIPs() failed:", err)
|
debug(LogError, "dumpIPs() failed:", err)
|
||||||
}
|
}
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
log.Println(host, ip)
|
log.Println(host, ip)
|
||||||
|
|
Loading…
Reference in New Issue