Sam Therapy
1b5d5a3fed
Some checks failed
continuous-integration/drone/push Build is failing
Signed-off-by: Sam Therapy <sam@samtherapy.net>
71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"encoding/xml"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.froth.zone/sam/awl/cli"
|
|
"git.froth.zone/sam/awl/query"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
var version = "DEV"
|
|
|
|
func main() {
|
|
opts, err := cli.ParseCLI(version)
|
|
if err != nil {
|
|
opts.Logger.Fatal(err)
|
|
os.Exit(1)
|
|
}
|
|
resp, err := query.CreateQuery(opts)
|
|
if err != nil {
|
|
opts.Logger.Fatal(err)
|
|
os.Exit(1)
|
|
}
|
|
switch {
|
|
case opts.JSON:
|
|
json, err := json.MarshalIndent(resp.DNS, "", " ")
|
|
if err != nil {
|
|
opts.Logger.Fatal(err)
|
|
os.Exit(1)
|
|
}
|
|
fmt.Println(string(json))
|
|
case opts.XML:
|
|
xml, err := xml.MarshalIndent(resp.DNS, "", " ")
|
|
if err != nil {
|
|
opts.Logger.Fatal(err)
|
|
os.Exit(1)
|
|
}
|
|
fmt.Println(string(xml))
|
|
case opts.YAML:
|
|
yaml, err := yaml.Marshal(resp.DNS)
|
|
if err != nil {
|
|
opts.Logger.Fatal(err)
|
|
os.Exit(1)
|
|
}
|
|
fmt.Println(string(yaml))
|
|
default:
|
|
if !opts.Short {
|
|
// Print everything
|
|
fmt.Println(resp.DNS)
|
|
fmt.Println(";; Query time:", resp.RTT)
|
|
fmt.Println(";; SERVER:", opts.Request.Server)
|
|
fmt.Println(";; WHEN:", time.Now().Format(time.RFC1123Z))
|
|
fmt.Println(";; MSG SIZE rcvd:", resp.DNS.Len())
|
|
} else {
|
|
// Print just the responses, nothing else
|
|
for _, res := range resp.DNS.Answer {
|
|
temp := strings.Split(res.String(), "\t")
|
|
fmt.Println(temp[len(temp)-1])
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|