forked from URLooker/web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns.go
44 lines (36 loc) · 963 Bytes
/
dns.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package utils
import (
"errors"
"fmt"
"strings"
"time"
"github.com/miekg/dns"
"github.com/urlooker/web/g"
)
func LookupIP(domain string, timeout int) ([]string, error) {
var c dns.Client
var err error
ips := []string{}
domain = strings.TrimRight(domain, ".") + "."
c.DialTimeout = time.Duration(timeout) * time.Millisecond
c.ReadTimeout = time.Duration(timeout) * time.Millisecond
c.WriteTimeout = time.Duration(timeout) * time.Millisecond
m := new(dns.Msg)
m.SetQuestion(domain, dns.TypeA)
ret, _, err := c.Exchange(m, "114.114.114.114:53")
if err != nil {
domain = strings.TrimRight(domain, ".")
e := fmt.Sprintf("lookup error: %s, %s", domain, err.Error())
return ips, errors.New(e)
}
for _, i := range ret.Answer {
result := strings.Split(i.String(), "\t")
if result[3] == "A" && IsIP(result[4]) {
ips = append(ips, result[4])
}
}
return ips, err
}
func InternalDns(domain string) []g.IpIdc {
return []g.IpIdc{}
}