add wireformat question creation from string or stdin
This commit is contained in:
parent
39d496cf7e
commit
74bdbb38ac
@ -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()
|
||||
|
@ -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 -`
|
||||
|
Loading…
Reference in New Issue
Block a user