add wireformat question creation from string or stdin
This commit is contained in:
parent
39d496cf7e
commit
74bdbb38ac
@ -1,18 +1,25 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
file := flag.String("f", "", "file path to read hexa decimal wireformat data")
|
file := flag.String("f", "", "file path to read hexa decimal wireformat data")
|
||||||
|
domainToResolve := flag.String("s", "-", "Server adress to resolve")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
// remove timestamp prefix from log out
|
||||||
|
log.SetFlags(0)
|
||||||
|
|
||||||
var body []byte
|
var body []byte
|
||||||
var err error
|
var err error
|
||||||
if *file != "" {
|
if *file != "" {
|
||||||
@ -31,6 +38,28 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Println(msg)
|
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 {
|
} else {
|
||||||
log.Println(errors.New("Too few argument pass"))
|
log.Println(errors.New("Too few argument pass"))
|
||||||
flag.Usage()
|
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 -`
|
`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