Browse Source

feat : add http dns resolver with cloudflare

master
Antoine 5 months ago
parent
commit
aa3931e6df
Signed by: antoine <antoinroux@hotmail.fr> GPG Key ID: 098FB66FC0475E70
3 changed files with 57 additions and 1 deletions
  1. +3
    -0
      Makefile
  2. +44
    -0
      cmd/dns/http-resolver.go
  3. +10
    -1
      readme.md

+ 3
- 0
Makefile View File

@@ -5,6 +5,9 @@ bin_path=./bin
wireformat:
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:
go fmt ./...


+ 44
- 0
cmd/dns/http-resolver.go View 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)
}

+ 10
- 1
readme.md View File

@@ -4,7 +4,10 @@ dns relative tools like lookup or wireformat converter

## build

`make wireformat`
```
make wireformat
make http-resolver
```

## run

@@ -21,3 +24,9 @@ Wireformat encode and decode
`./bin/wireformat -s 'www.example.com' | ./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…
Cancel
Save