Skip to content

Commit

Permalink
Merge pull request #80 from sooraj-sky/dns
Browse files Browse the repository at this point in the history
added DNS
  • Loading branch information
sooraj-sky authored Feb 25, 2023
2 parents 5774b9a + f101602 commit 978b20e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/alerts/skydns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package skydns

import (
"context"
"net"
"time"
)

// Create a custom Resolver that uses a specific DNS server IP
func customResolver(dnsServer string) *net.Resolver {
return &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
dialer := net.Dialer{
Timeout: 10 * time.Second,
Resolver: &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
return (&net.Dialer{
Timeout: 10 * time.Second,
DualStack: true,
}).DialContext(ctx, network, dnsServer+":53")
},
},
}
return dialer.DialContext(ctx, network, address)
},
}
}
5 changes: 5 additions & 0 deletions packages/httpres/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

models "github.com/sooraj-sky/sky-meter/models"
skydns "github.com/sooraj-sky/sky-meter/packages/skydns"
)

func GetHttpdata(url string, timeout time.Duration, SkipSsl bool) (httpdata []byte, httpstatuscode int, errs error) {
Expand Down Expand Up @@ -57,6 +58,10 @@ func trace() (*httptrace.ClientTrace, *models.Debug) {
d := &models.Debug{}

t := &httptrace.ClientTrace{
//DNS settings
dnsServer := "8.8.8.8" // Replace with your desired DNS server IP address
skydns.resolver := customResolver(dnsServer)

DNSStart: func(info httptrace.DNSStartInfo) {
t := time.Now().UTC().String()
//log.Println(t, "dns start")
Expand Down

0 comments on commit 978b20e

Please sign in to comment.