parent
57b0942cc7
commit
62ee9ec28c
137
digStatus.go
137
digStatus.go
|
@ -17,7 +17,6 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
"strings"
|
||||
"strconv"
|
||||
"reflect"
|
||||
"errors"
|
||||
|
||||
|
@ -25,8 +24,6 @@ import (
|
|||
"go.wit.com/gui/gui"
|
||||
"go.wit.com/gui/gadgets"
|
||||
"go.wit.com/shell"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
type digStatus struct {
|
||||
|
@ -58,34 +55,6 @@ type digStatus struct {
|
|||
statusHTTP *gadgets.OneLiner
|
||||
}
|
||||
|
||||
type dnsStatus struct {
|
||||
title string
|
||||
server string // The DNS server. Example: "127.0.0.1:53" or "1.1.1.1:53"
|
||||
hostname string // the hostname to lookup. Example: "www.google.com" or "go.wit.com"
|
||||
|
||||
parent *gui.Node
|
||||
group *gui.Node
|
||||
grid *gui.Node
|
||||
|
||||
// DNS setup options
|
||||
udpA *gui.Node
|
||||
tcpA *gui.Node
|
||||
udpAAAA *gui.Node
|
||||
tcpAAAA *gui.Node
|
||||
|
||||
// show the display
|
||||
aFail *gui.Node
|
||||
aSuccess *gui.Node
|
||||
aaaaFail *gui.Node
|
||||
aaaaSuccess *gui.Node
|
||||
|
||||
// interger counters
|
||||
aFailc int
|
||||
aSuccessc int
|
||||
aaaaFailc int
|
||||
aaaaSuccessc int
|
||||
}
|
||||
|
||||
func NewDigStatusWindow(p *gui.Node) *digStatus {
|
||||
var ds *digStatus
|
||||
ds = new(digStatus)
|
||||
|
@ -111,7 +80,7 @@ func NewDigStatusWindow(p *gui.Node) *digStatus {
|
|||
// make the area to store the raw details
|
||||
ds.details = ds.window.Box().NewGroup("Details")
|
||||
ds.dsLocalhost = NewResolverStatus(ds.details, "(localhost)", "127.0.0.1:53", "go.wit.com")
|
||||
ds.dsLocalNetwork = NewResolverStatus(ds.details, "(Local Network)", "172.22.0.1:53", "go.wit.com")
|
||||
ds.dsLocalNetwork = NewResolverStatus(ds.details, "(Local Network)", "192.168.86.1:53", "go.wit.com")
|
||||
ds.dsCloudflare = NewResolverStatus(ds.details, "(cloudflare)", "1.1.1.1:53", "go.wit.com")
|
||||
ds.dsGoogle = NewResolverStatus(ds.details, "(google)", "8.8.8.8:53", "go.wit.com")
|
||||
ds.makeDnsStatusGrid()
|
||||
|
@ -278,110 +247,6 @@ func (ds *digStatus) updateDnsStatus() {
|
|||
me.digStatus.set(ds.DnsDigTCP, out)
|
||||
}
|
||||
|
||||
// Makes a DNS Status Grid
|
||||
func NewDnsStatus(p *gui.Node, title string, server string, hostname string) *dnsStatus {
|
||||
var ds *dnsStatus
|
||||
ds = new(dnsStatus)
|
||||
ds.parent = p
|
||||
ds.group = p.NewGroup(server + " " + title + " lookup")
|
||||
ds.grid = ds.group.NewGrid("LookupStatus", 5, 2)
|
||||
|
||||
ds.server = server
|
||||
ds.hostname = hostname
|
||||
|
||||
ds.grid.NewLabel("")
|
||||
ds.grid.NewLabel("UDP")
|
||||
ds.grid.NewLabel("TCP")
|
||||
ds.grid.NewLabel("Success")
|
||||
ds.grid.NewLabel("Fail")
|
||||
|
||||
ds.grid.NewLabel("A")
|
||||
ds.udpA = ds.grid.NewLabel("?")
|
||||
ds.tcpA = ds.grid.NewLabel("?")
|
||||
ds.aSuccess = ds.grid.NewLabel("?")
|
||||
ds.aFail = ds.grid.NewLabel("?")
|
||||
|
||||
ds.grid.NewLabel("AAAA")
|
||||
ds.udpAAAA = ds.grid.NewLabel("?")
|
||||
ds.tcpAAAA = ds.grid.NewLabel("?")
|
||||
ds.aaaaSuccess = ds.grid.NewLabel("?")
|
||||
ds.aaaaFail = ds.grid.NewLabel("?")
|
||||
|
||||
ds.group.Margin()
|
||||
ds.grid.Margin()
|
||||
ds.group.Pad()
|
||||
ds.grid.Pad()
|
||||
|
||||
return ds
|
||||
}
|
||||
|
||||
// special thanks to the Element Hotel wifi in Philidelphia that allowed me to
|
||||
// easily debug this code since the internet connection here blocks port 53 traffic
|
||||
func (ds *dnsStatus) update() (bool, bool) {
|
||||
var results []string
|
||||
var a bool = false
|
||||
var aaaa bool = false
|
||||
|
||||
log.Log(DNS, "dnsStatus.update() For server", ds.server, "on", ds.hostname)
|
||||
results, _ = dnsUdpLookup(ds.server, ds.hostname, dns.TypeA)
|
||||
log.Log(DNS, "dnsStatus.update() UDP type A =", results)
|
||||
|
||||
if (len(results) == 0) {
|
||||
me.digStatus.set(ds.udpA, "BROKEN")
|
||||
ds.aFailc += 1
|
||||
} else {
|
||||
me.digStatus.set(ds.udpA, "WORKING")
|
||||
ds.aSuccessc += 1
|
||||
a = true
|
||||
}
|
||||
|
||||
results, _ = dnsTcpLookup(ds.server, ds.hostname, dns.TypeA)
|
||||
log.Log(DNS, "dnsStatus.update() TCP type A =", results)
|
||||
|
||||
if (len(results) == 0) {
|
||||
me.digStatus.set(ds.tcpA, "BROKEN")
|
||||
ds.aFailc += 1
|
||||
} else {
|
||||
me.digStatus.set(ds.tcpA, "WORKING")
|
||||
ds.aSuccessc += 1
|
||||
a = true
|
||||
}
|
||||
|
||||
me.digStatus.set(ds.aFail, strconv.Itoa(ds.aFailc))
|
||||
me.digStatus.set(ds.aSuccess,strconv.Itoa(ds.aSuccessc))
|
||||
|
||||
results, _ = dnsUdpLookup(ds.server, ds.hostname, dns.TypeAAAA)
|
||||
log.Log(DNS, "dnsStatus.update() UDP type AAAA =", results)
|
||||
|
||||
if (len(results) == 0) {
|
||||
me.digStatus.set(ds.udpAAAA, "BROKEN")
|
||||
ds.aaaaFailc += 1
|
||||
me.digStatus.set(ds.aaaaFail, strconv.Itoa(ds.aaaaFailc))
|
||||
} else {
|
||||
me.digStatus.set(ds.udpAAAA, "WORKING")
|
||||
ds.aaaaSuccessc += 1
|
||||
aaaa = true
|
||||
}
|
||||
|
||||
results, _ = dnsTcpLookup(ds.server, ds.hostname, dns.TypeAAAA)
|
||||
log.Log(DNS, "dnsStatus.update() UDP type AAAA =", results)
|
||||
|
||||
if (len(results) == 0) {
|
||||
me.digStatus.set(ds.tcpAAAA, "BROKEN")
|
||||
ds.aaaaFailc += 1
|
||||
me.digStatus.set(ds.aaaaFail, strconv.Itoa(ds.aaaaFailc))
|
||||
} else {
|
||||
me.digStatus.set(ds.tcpAAAA, "WORKING")
|
||||
ds.aaaaSuccessc += 1
|
||||
aaaa = true
|
||||
}
|
||||
|
||||
me.digStatus.set(ds.aaaaFail, strconv.Itoa(ds.aaaaFailc))
|
||||
me.digStatus.set(ds.aaaaSuccess,strconv.Itoa(ds.aaaaSuccessc))
|
||||
|
||||
return a, aaaa
|
||||
}
|
||||
|
||||
func (ds *digStatus) makeHttpStatusGrid() {
|
||||
group := ds.details.NewGroup("dns.google.com via HTTPS")
|
||||
grid := group.NewGrid("LookupStatus", 2, 2)
|
||||
|
|
46
dns-https.go
46
dns-https.go
|
@ -8,52 +8,6 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
/*
|
||||
// dnsLookupDoH performs a DNS lookup for AAAA records over HTTPS.
|
||||
func dnsAAAAlookupDoHold(hostname string) ([]string, error) {
|
||||
var ipv6Addresses []string
|
||||
|
||||
// Construct the URL for a DNS query with Google's DNS-over-HTTPS API
|
||||
url := fmt.Sprintf("https://dns.google.com/resolve?name=%s&type=AAAA", hostname)
|
||||
|
||||
log.Log(DNS, "dnsAAAAlookupDoH()", url)
|
||||
if hostname == "" {
|
||||
log.Warn("dnsAAAAlookupDoH() was sent a empty hostname")
|
||||
return nil, fmt.Errorf("hostname blank")
|
||||
}
|
||||
|
||||
// Perform the HTTP GET request
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error performing DNS-over-HTTPS request: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Read and unmarshal the response body
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading response: %w", err)
|
||||
}
|
||||
|
||||
var data struct {
|
||||
Answer []struct {
|
||||
Data string `json:"data"`
|
||||
} `json:"Answer"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(body, &data); err != nil {
|
||||
return nil, fmt.Errorf("error unmarshaling response: %w", err)
|
||||
}
|
||||
|
||||
// Extract the IPv6 addresses
|
||||
for _, answer := range data.Answer {
|
||||
ipv6Addresses = append(ipv6Addresses, answer.Data)
|
||||
}
|
||||
|
||||
return ipv6Addresses, nil
|
||||
}
|
||||
*/
|
||||
|
||||
// dnsLookupDoH performs a DNS lookup for AAAA records over HTTPS.
|
||||
func lookupDoH(hostname string, rrType string) []string {
|
||||
var values []string
|
||||
|
|
24
hostname.go
24
hostname.go
|
@ -86,30 +86,6 @@ func goodHostname() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
/*
|
||||
func digAAAA(s string) []string {
|
||||
var aaaa []string
|
||||
// lookup the IP address from DNS
|
||||
rrset := dnssecsocket.Dnstrace(s, "AAAA")
|
||||
// log.Spew(args.VerboseDNS, SPEW, rrset)
|
||||
for i, rr := range rrset {
|
||||
ipaddr := dns.Field(rr, 1)
|
||||
// how the hell do you detect a RRSIG AAAA record here?
|
||||
if (ipaddr == "28") {
|
||||
continue
|
||||
}
|
||||
log.Log(NOW, "r.Answer =", i, "rr =", rr, "ipaddr =", ipaddr)
|
||||
aaaa = append(aaaa, ipaddr)
|
||||
me.ipv6s[ipaddr] = rr
|
||||
}
|
||||
log.Info(args.VerboseDNS, "aaaa =", aaaa)
|
||||
log.Println("digAAAA() returned =", aaaa)
|
||||
log.Println("digAAAA() me.ipv6s =", me.ipv6s)
|
||||
os.Exit(0)
|
||||
return aaaa
|
||||
}
|
||||
*/
|
||||
|
||||
func digAAAA(hostname string) []string {
|
||||
var blah, ipv6Addresses []string
|
||||
// domain := hostname
|
||||
|
|
Loading…
Reference in New Issue