Skip to content

Commit

Permalink
Merge branch 'release/0.0.2' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisryan911127 committed Mar 7, 2023
2 parents 8e35df1 + f16f32b commit ce79c2f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# doh

![golang-doh](https://img.shields.io/static/v1?label=golang&message=doh&color=blue&style=for-the-badge&logo=go)
![build-status](https://img.shields.io/github/workflow/status/nayrsirhc/doh/CI?style=for-the-badge)
![build-status](https://img.shields.io/github/actions/workflow/status/nayrsirhc/doh/ci.yml?style=for-the-badge)

The purpose of this command and project in general, is to solve the problem of being terminal first, working behind a corporate firewall can be challenging, you might want to see what a DNS record resolves to externally, but port 53 is blocked for security reasons, DNS over HTTPS obviously uses port 443 to do so hence the birth of this command.

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ module github.com/nayrsirhc/doh

go 1.18

require github.com/spf13/cobra v1.6.1 // direct

require (
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/spf13/cobra v1.6.1 // direct
github.com/spf13/pflag v1.0.5 // indirect
)
14 changes: 9 additions & 5 deletions pkg/doh/doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ type DNSRecord struct {
} `json:"Answer"`
}

func LogError(err error) {
if err != nil {
time.Sleep(1 * time.Second)
log.Fatalln(err)
}
}
// DOHRequest Makes a DNS-over-HTTP request which takes different providers, eg. Google, Cloudflare
func DOHRequest(provider string, recordName string, recordType string) (body []byte) {
var resolveQuery string
Expand All @@ -36,20 +42,18 @@ func DOHRequest(provider string, recordName string, recordType string) (body []b

req, err := http.NewRequest("GET", resolveQuery, nil)
if err != nil {
log.Fatalln(err)
LogError(err)
}
req.Header.Set("accept", "application/dns-json")
//We Read the response body on the line below.
client := &http.Client{}
resp, err := client.Do(req)

if err != nil {
log.Fatalln(err)
LogError(err)
}

body, err = ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
LogError(err)
}

return body
Expand Down

0 comments on commit ce79c2f

Please sign in to comment.