summaryrefslogtreecommitdiff
path: root/util/dns_resolver.go
blob: feda4801530c0058757f959b938aaf150dc4a206 (plain)
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
package util

import (
	"errors"
	"net"
)

func DnsResolver(addrType int) (string, error) {
	dns := "www.netflix.com"

	if ns, err := net.LookupHost(dns); err != nil {
		return "", err
	} else {
		switch {
		case len(ns) != 0:
			for _, n := range ns {
				if ParseIP(n) == 4 && addrType == 4 {
					return n, nil
				}
				if ParseIP(n) == 6 && addrType == 6 {
					return "[" + n + "]", nil
				}
			}
		}
	}
	return "", errors.New("no IP Address")
}