Skip to content

Commit 43682c0

Browse files
committed
Refactor
1 parent 9ceb7c2 commit 43682c0

File tree

4 files changed

+25
-34
lines changed

4 files changed

+25
-34
lines changed

check/glue.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (g *Glue) getGlueIPs(domain string, server string) ([]net.IP, error) {
130130
log.Debugf("GLUE: getGlueIPs")
131131
defer log.Debugf("GLUE: getGlueIPs exit")
132132
var ips []net.IP
133-
res, err := g.s.Query(domain, dns.TypeNS, server, true)
133+
res, err := scan.Query(domain, dns.TypeNS, server, true)
134134
if err != nil {
135135
return ips, err
136136
}

main.go

+16-13
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func printHelp() {
3737
flag.PrintDefaults()
3838
}
3939

40-
func main() {
40+
func initScan() *scan.Scan {
4141
var resolver string
4242
flagDebug = flag.Bool("debug", false, "enable debug")
4343
flagScan = flag.Bool("scan", false, "scan domain for common records")
@@ -49,7 +49,7 @@ func main() {
4949

5050
if len(flag.Args()) == 0 {
5151
printHelp()
52-
return
52+
os.Exit(0)
5353
}
5454

5555
if *flagDebug {
@@ -58,13 +58,17 @@ func main() {
5858
if !*flagJSON {
5959
fmt.Printf("using %s as resolver\n", resolver)
6060
}
61-
62-
domain := flag.Arg(0)
6361
s := scan.New(&scan.Config{
6462
JSON: flagJSON,
6563
Debug: flagDebug,
6664
QPS: flagQPS,
6765
}, resolver)
66+
return s
67+
}
68+
69+
func main() {
70+
s := initScan()
71+
domain := flag.Arg(0)
6872
nsdatas, err := s.FindNS(dns.Fqdn(domain))
6973
if len(nsdatas) == 0 {
7074
fmt.Println("no nameservers found for", domain)
@@ -76,15 +80,6 @@ func main() {
7680
}
7781
var domainReport check.DomainReport
7882
createNSHeader(s, domain, nsdatas, &domainReport)
79-
80-
// enable debug again if needed
81-
if *flagDebug {
82-
log.Level = logrus.DebugLevel
83-
}
84-
85-
if !IPv6Guess {
86-
nsdatas = removeIPv6(nsdatas)
87-
}
8883
doDomainReport(s, domain, nsdatas, &domainReport)
8984
}
9085

@@ -106,6 +101,9 @@ func execCheckers(s *scan.Scan, domain string, nsdatas []structs.NSData, domainR
106101
}
107102

108103
func doDomainReport(s *scan.Scan, domain string, nsdatas []structs.NSData, domainReport *check.DomainReport) {
104+
if !IPv6Guess {
105+
nsdatas = removeIPv6(nsdatas)
106+
}
109107
domainReport.Name = domain
110108
sp := spinner.New(spinner.CharSets[14], 100*time.Millisecond)
111109
sp.Writer = os.Stderr
@@ -181,4 +179,9 @@ func createNSHeader(s *scan.Scan, domain string, nsdatas []structs.NSData, domai
181179
close(wc)
182180
sp.Stop()
183181
<-done
182+
183+
//enable debug again
184+
if *flagDebug {
185+
log.Level = logrus.DebugLevel
186+
}
184187
}

scan/scan.go

+8
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,11 @@ func (s *Scan) Resolver() string {
295295
func (s *Scan) NSData() map[string][]structs.NSData {
296296
return s.nsdataCache
297297
}
298+
299+
func Query(q string, qtype uint16, server string, sec bool) (structs.Response, error) {
300+
return query(q, qtype, server, sec)
301+
}
302+
303+
func QueryRRset(q string, qtype uint16, server string, sec bool) ([]dns.RR, time.Duration, error) {
304+
return queryRRset(q, qtype, server, sec)
305+
}

scan/utils.go

-20
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ func extractIP(rrset []dns.RR) []net.IP {
3535
return ips
3636
}
3737

38-
func (s *Scan) ExtractRR(rrset []dns.RR, qtypes ...uint16) []dns.RR {
39-
return extractRR(rrset, qtypes...)
40-
}
41-
4238
func extractRR(rrset []dns.RR, qtypes ...uint16) []dns.RR {
4339
var out []dns.RR
4440
m := make(map[uint16]bool)
@@ -53,14 +49,6 @@ func extractRR(rrset []dns.RR, qtypes ...uint16) []dns.RR {
5349
return out
5450
}
5551

56-
func (s *Scan) Query(q string, qtype uint16, server string, sec bool) (structs.Response, error) {
57-
return query(q, qtype, server, sec)
58-
}
59-
60-
func Query(q string, qtype uint16, server string, sec bool) (structs.Response, error) {
61-
return query(q, qtype, server, sec)
62-
}
63-
6452
func query(q string, qtype uint16, server string, sec bool) (structs.Response, error) {
6553
c := new(dns.Client)
6654
m := prepMsg()
@@ -88,14 +76,6 @@ func query(q string, qtype uint16, server string, sec bool) (structs.Response, e
8876
return structs.Response{Msg: in, Server: server, Rtt: rtt}, nil
8977
}
9078

91-
func (s *Scan) QueryRRset(q string, qtype uint16, server string, sec bool) ([]dns.RR, time.Duration, error) {
92-
return queryRRset(q, qtype, server, sec)
93-
}
94-
95-
func QueryRRset(q string, qtype uint16, server string, sec bool) ([]dns.RR, time.Duration, error) {
96-
return queryRRset(q, qtype, server, sec)
97-
}
98-
9979
func queryRRset(q string, qtype uint16, server string, sec bool) ([]dns.RR, time.Duration, error) {
10080
res, err := query(q, qtype, server, sec)
10181
if err != nil {

0 commit comments

Comments
 (0)