add wireformat question creation from string or stdin

This commit is contained in:
Antoine 2020-11-09 02:18:51 +01:00
parent 39d496cf7e
commit 74bdbb38ac
Signed by: antoine
GPG Key ID: 098FB66FC0475E70
2 changed files with 34 additions and 0 deletions

View File

@ -1,18 +1,25 @@
package main
import (
"encoding/binary"
"errors"
"flag"
"io/ioutil"
"log"
"os"
"strings"
"github.com/miekg/dns"
)
func main() {
file := flag.String("f", "", "file path to read hexa decimal wireformat data")
domainToResolve := flag.String("s", "-", "Server adress to resolve")
flag.Parse()
// remove timestamp prefix from log out
log.SetFlags(0)
var body []byte
var err error
if *file != "" {
@ -31,6 +38,28 @@ func main() {
}
log.Println(msg)
} else if *domainToResolve != "" {
if *domainToResolve == "-" {
readDomainToResolve, err := ioutil.ReadFile("/dev/stdin")
if err != nil {
log.Fatalln(err)
}
*domainToResolve = strings.TrimSuffix(string(readDomainToResolve), "\n")
}
msg := &dns.Msg{
Question: []dns.Question{
dns.Question{
dns.Fqdn(*domainToResolve),
dns.TypeANY,
dns.ClassINET,
},
},
}
b, err := msg.Pack()
if err != nil {
log.Fatalln(err)
}
binary.Write(os.Stdout, binary.LittleEndian, b)
} else {
log.Println(errors.New("Too few argument pass"))
flag.Usage()

View File

@ -16,3 +16,8 @@ With post resolution
`curl -s -H accept: application/dns-message https://cloudflare-dns.com/dns-query?dns=q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB | ./bin/wireformat -f -`
Wireformat encode and decode
`./bin/wireformat -s 'www.example.com' | ./bin/wireformat -f -`
`echo 'www.example.com' | ./bin/wireformat | ./bin/wireformat -f -`