This commit is contained in:
Matt Burchett 2018-11-30 12:24:57 -06:00
parent 693a6d411a
commit 9209c26864
2 changed files with 23 additions and 18 deletions

View File

@ -3,11 +3,11 @@ package model
type Results struct { type Results struct {
IP string `json:"ip"` IP string `json:"ip"`
Hostname string `json:"hostname"` Hostname string `json:"hostname"`
TXT string `json:"TXT,omitempty"` TXT string `json:"TXT`
} }
type UniqResults struct { type UniqResults struct {
IP string `json:"ip"` IP string `json:"ip"`
Hostname string `json:"hostname"` Hostname string `json:"hostname"`
TXT string `json:"TXT,omitempty"` TXT string `json:"TXT"`
} }

View File

@ -1,12 +1,14 @@
package resolver package resolver
import ( import (
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"log" "log"
"strings" "strings"
"git.linuxrocker.com/mattburchett/go_tab-magic/pkg/config" "git.linuxrocker.com/mattburchett/go_tab-magic/pkg/config"
"git.linuxrocker.com/mattburchett/go_tab-magic/pkg/model"
"github.com/miekg/dns" "github.com/miekg/dns"
) )
@ -66,24 +68,27 @@ func PerformZoneTransfer(config config.Config) {
default: default:
continue continue
} }
// data = append(data, fmt.Sprintf("%v %v %v\n", strings.TrimRight(hostname, "."), ip, txt))
for _, i := range data {
checkval := fmt.Sprintf("%v %v ", strings.TrimRight(hostname, "."), ip)
fmt.Printf("CheckVal: %v", checkval)
actualval := fmt.Sprintf("%v %v %v", strings.TrimRight(hostname, "."), ip, txt)
fmt.Printf("ActualVal: %v", actualval)
if i == checkval {
if i != actualval {
i = actualval
}
} else {
data = append(data, fmt.Sprintf("%v %v %v\n", strings.TrimRight(hostname, "."), ip, txt)) data = append(data, fmt.Sprintf("%v %v %v\n", strings.TrimRight(hostname, "."), ip, txt))
} }
} }
} }
}
}
fmt.Println(data) fmt.Println(data)
resultsToJSON(data)
}
func resultsToJSON(data []string) {
for _, i := range data {
splitStrings := strings.Split(i, " ")
hostname := splitStrings[1]
ip := splitStrings[2]
txt := splitStrings[3]
dns := &model.Results{IP: ip, Hostname: hostname, TXT: txt}
b, err := json.Marshal(dns)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(b))
}
} }