-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprinter.go
62 lines (53 loc) · 1.74 KB
/
printer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"os"
"sync"
"time"
"github.com/Sirupsen/logrus"
"github.com/olekukonko/tablewriter"
)
// printResponse prints CDN info to stdout, no error is checked
func query(domain string, ns nsInfo, showDNSErrors bool, dnsTimeout time.Duration, results chan Results, wg *sync.WaitGroup) error {
defer wg.Done()
cname, took, err := getCNAME(domain, ns.ip, showDNSErrors, dnsTimeout)
if err != nil {
if showDNSErrors {
logrus.Warningf("Couldn't resolve domain: %s via ns: %s, Error: %s", domain, ns, err)
}
return fmt.Errorf("Error resolving domain: %s via ns: %s, Error: %s", domain, ns, err)
}
cdn, err := getCDN(cname)
if err != nil {
logrus.Warningf("Couldn't get CDN name from hostname %s, Error: %s", cname, err)
}
countryName, ok := ccMap[ns.country_id]
// Only show complete information
if ok && cdn != "" {
// logrus.Infof("%s (%s:%s): %s (%s)", countryName, ns.country_id, ns.city, cdn, cname)
result := Results{
cdn: cdn,
countryName: countryName,
nameserver: ns,
cname: cname,
responseTime: took,
}
results <- result
}
return nil
}
func printTable(results chan Results, wg *sync.WaitGroup) {
defer wg.Done()
table := tablewriter.NewWriter(os.Stdout)
headers := []string{"Country", "City", "CDN/Hostname", "IP", "Time"}
table.SetColWidth(60)
table.SetHeader(headers)
table.SetBorders(tablewriter.Border{Left: true, Top: true, Right: true, Bottom: true})
table.SetCenterSeparator("|")
for r := range results {
city := fmt.Sprintf("%s - %-15s", r.nameserver.country_id, r.nameserver.city)
cdnHostname := fmt.Sprintf("%-10s - %s", r.cdn, r.cname)
table.Append([]string{r.countryName, city, cdnHostname, r.nameserver.ip, r.responseTime.String()})
}
table.Render()
}