dns


TXT lookup example

Node.js

  1. const dns = require('dns')
  2. dns.resolve4('google.com', (err, ips) => {
  3. if (err) {
  4. console.error(err)
  5. }
  6. console.log(ips)
  7. })
  8. dns.resolveMx('google.com', (err, mx) => {
  9. if (err) {
  10. console.error(err)
  11. }
  12. console.log(mx)
  13. })
  14. dns.resolveTxt('google.com', (err, txt) => {
  15. if (err) {
  16. console.error(err)
  17. }
  18. console.log(txt)
  19. })

Output

  1. [ '172.217.11.78' ]
  2. [ { exchange: 'alt4.aspmx.l.google.com', priority: 50 },
  3. { exchange: 'alt2.aspmx.l.google.com', priority: 30 },
  4. { exchange: 'alt3.aspmx.l.google.com', priority: 40 },
  5. { exchange: 'aspmx.l.google.com', priority: 10 },
  6. { exchange: 'alt1.aspmx.l.google.com', priority: 20 } ]
  7. [ [ 'v=spf1 include:_spf.google.com ~all' ],
  8. [ 'docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e' ],
  9. [ 'facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95' ],
  10. [ 'globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8=' ] ]

Go

  1. package main
  2. import (
  3. "fmt"
  4. "net"
  5. )
  6. func main() {
  7. ips, err := net.LookupIP("google.com")
  8. if err != nil {
  9. panic(err)
  10. }
  11. fmt.Println(ips)
  12. mx, err := net.LookupMX("google.com")
  13. if err != nil {
  14. panic(err)
  15. }
  16. fmt.Println(mx)
  17. txt, err := net.LookupTXT("google.com")
  18. if err != nil {
  19. panic(err)
  20. }
  21. fmt.Println(txt)
  22. }

Output

  1. [172.217.5.78 2607:f8b0:4007:80d::200e]
  2. [0xc0000ba2e0 0xc0000ba260 0xc0000ba2a0 0xc0000ba280 0xc0000ba300]
  3. [facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95 docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e v=spf1 include:_spf.google.com ~all globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8=]