Skip to content

Commit

Permalink
Merge pull request #3 from projectdiscovery/feature-do-function
Browse files Browse the repository at this point in the history
Default Do function like net.http
  • Loading branch information
Mzack9999 committed Apr 23, 2020
2 parents c6b23d0 + 03765ab commit f8a7548
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,27 @@ func (c *Client) ResolveRaw(host string, requestType uint16) (results []string,
return results, err
}

// Do sends a provided dns request and return the raw native response
func (c *Client) Do(msg *dns.Msg) (resp *dns.Msg, err error) {
resolver := c.resolvers[rand.Intn(len(c.resolvers))]

var answer *dns.Msg

for i := 0; i < c.maxRetries; i++ {
answer, err = dns.Exchange(msg, resolver)
if err != nil {
continue
}

// In case we get a non empty answer stop retrying
if answer != nil {
return answer, nil
}
}

return nil, err
}

func parse(answer *dns.Msg, requestType uint16) (results []string) {
for _, record := range answer.Answer {
switch requestType {
Expand Down

0 comments on commit f8a7548

Please sign in to comment.