dns
DNS lookup examples
# Node.js
const dns = require("dns");
dns.resolveNs("google.com", (err, ns) => {
if (err) {
console.error(err);
}
console.log(ns);
});
dns.resolve4("google.com", (err, ips) => {
if (err) {
console.error(err);
}
console.log(ips);
});
dns.resolveMx("google.com", (err, mx) => {
if (err) {
console.error(err);
}
console.log(mx);
});
dns.resolveTxt("google.com", (err, txt) => {
if (err) {
console.error(err);
}
console.log(txt);
});
dns.setServers(["1.1.1.1"]);
console.log(dns.getServers());
dns.resolveNs("google.com", (err, ns) => {
if (err) {
console.error(err);
}
console.log(ns);
});
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
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
Output
[
'ns2.google.com',
'ns3.google.com',
'ns4.google.com',
'ns1.google.com'
]
[ '172.217.11.78' ]
[ { exchange: 'alt4.aspmx.l.google.com', priority: 50 },
{ exchange: 'alt2.aspmx.l.google.com', priority: 30 },
{ exchange: 'alt3.aspmx.l.google.com', priority: 40 },
{ exchange: 'aspmx.l.google.com', priority: 10 },
{ exchange: 'alt1.aspmx.l.google.com', priority: 20 } ]
[ [ 'v=spf1 include:_spf.google.com ~all' ],
[ 'docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e' ],
[ 'facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95' ],
[ 'globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8=' ] ]
[ '1.1.1.1' ]
[
'ns1.google.com',
'ns2.google.com',
'ns4.google.com',
'ns3.google.com'
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Go
package main
import (
"fmt"
"net"
)
func main() {
ns, err := net.LookupNS("google.com")
if err != nil {
panic(err)
}
fmt.Printf("%s\n", ns)
ips, err := net.LookupIP("google.com")
if err != nil {
panic(err)
}
fmt.Println(ips)
mx, err := net.LookupMX("google.com")
if err != nil {
panic(err)
}
fmt.Println(mx)
txt, err := net.LookupTXT("google.com")
if err != nil {
panic(err)
}
fmt.Println(txt)
r := &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
Timeout: time.Millisecond * time.Duration(10_000),
}
return d.DialContext(ctx, "udp", "1.1.1.1:53")
},
}
ns, _ = r.LookupNS(context.Background(), "google.com")
fmt.Printf("%s", ns)
}
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
45
46
47
48
49
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
45
46
47
48
49
Output
[%!s(*net.NS=&{ns3.google.com.}) %!s(*net.NS=&{ns4.google.com.}) %!s(*net.NS=&{ns1.google.com.}) %!s(*net.NS=&{ns2.google.com.})]
[172.217.5.78 2607:f8b0:4007:80d::200e]
[0xc0000ba2e0 0xc0000ba260 0xc0000ba2a0 0xc0000ba280 0xc0000ba300]
[facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95 docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e v=spf1 include:_spf.google.com ~all globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8=]
[%!s(*net.NS=&{ns2.google.com.}) %!s(*net.NS=&{ns1.google.com.}) %!s(*net.NS=&{ns3.google.com.}) %!s(*net.NS=&{ns4.google.com.})]
1
2
3
4
5
2
3
4
5
编辑 (opens new window)
上次更新: 2022/09/30, 11:34:22