feat : add http dns resolver with cloudflare
This commit is contained in:
parent
a19dbb1808
commit
aa3931e6df
3
Makefile
3
Makefile
@ -5,6 +5,9 @@ bin_path=./bin
|
|||||||
wireformat:
|
wireformat:
|
||||||
go build -o $(bin_path)/wireformat cmd/wireformat/wireformat.go
|
go build -o $(bin_path)/wireformat cmd/wireformat/wireformat.go
|
||||||
|
|
||||||
|
http-resolver:
|
||||||
|
go build -o $(bin_path)/http-resolver cmd/dns/http-resolver.go
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
|
|
||||||
|
44
cmd/dns/http-resolver.go
Normal file
44
cmd/dns/http-resolver.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/binary"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
check "antoine-roux.ml/projects/go/dns-tools/internal"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DnsResolverUrl = "https://cloudflare-dns.com/dns-query"
|
||||||
|
DnsMethod = "POST"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
// Remove timestamp prefix from log out
|
||||||
|
log.SetFlags(0)
|
||||||
|
|
||||||
|
// Read wireformat from stdin
|
||||||
|
data, err := ioutil.ReadFile(os.Stdin.Name())
|
||||||
|
check.Check(err)
|
||||||
|
|
||||||
|
// Create dns-message post request
|
||||||
|
client := &http.Client{}
|
||||||
|
req, err := http.NewRequest(DnsMethod, DnsResolverUrl, bytes.NewReader(data))
|
||||||
|
req.Header.Add("Content-type", "application/dns-message")
|
||||||
|
check.Check(err)
|
||||||
|
|
||||||
|
// Do post request
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
check.Check(err)
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// Read http response and Print wireformat to stdout
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
check.Check(err)
|
||||||
|
|
||||||
|
binary.Write(os.Stdout, binary.LittleEndian, body)
|
||||||
|
}
|
11
readme.md
11
readme.md
@ -4,7 +4,10 @@ dns relative tools like lookup or wireformat converter
|
|||||||
|
|
||||||
## build
|
## build
|
||||||
|
|
||||||
`make wireformat`
|
```
|
||||||
|
make wireformat
|
||||||
|
make http-resolver
|
||||||
|
```
|
||||||
|
|
||||||
## run
|
## run
|
||||||
|
|
||||||
@ -21,3 +24,9 @@ Wireformat encode and decode
|
|||||||
`./bin/wireformat -s 'www.example.com' | ./bin/wireformat -f -`
|
`./bin/wireformat -s 'www.example.com' | ./bin/wireformat -f -`
|
||||||
|
|
||||||
`echo 'www.example.com' | ./bin/wireformat | ./bin/wireformat -f -`
|
`echo 'www.example.com' | ./bin/wireformat | ./bin/wireformat -f -`
|
||||||
|
|
||||||
|
|
||||||
|
Dns query and wireformat encode/decode
|
||||||
|
|
||||||
|
`echo 'www.google.com' | ./bin/wireformat -s - | ./bin/http-resolver | ./bin/wireformat -f -`
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user