Beispiel #1
0
func Getaddr(lookuper sutils.Lookuper, hostname string) (ip net.IP) {
	ip = net.ParseIP(hostname)
	if ip != nil {
		return
	}
	addrs, err := lookuper.LookupIP(hostname)
	n := len(addrs)
	if err != nil || n == 0 {
		return nil
	}
	return addrs[rand.Intn(n)]
}
Beispiel #2
0
func Getaddrs(lookuper sutils.Lookuper, hostname string) (ips []net.IP) {
	ip := net.ParseIP(hostname)
	if ip != nil {
		ips = append(ips, ip)
		return
	}
	ips, err := lookuper.LookupIP(hostname)
	if err != nil {
		log.Error("%s", err.Error())
	}
	return
}
Beispiel #3
0
func Getaddr(lookuper sutils.Lookuper, hostname string) (ip net.IP) {
	ip = net.ParseIP(hostname)
	if ip != nil {
		return
	}
	addrs, err := lookuper.LookupIP(hostname)

	n := len(addrs)
	if err != nil {
		return nil
	}
	switch n {
	case 0:
		return nil
	case 1:
		return addrs[0]
	default:
		return addrs[rand.Intn(n)]
	}
}