2015-07-26 16:33:29 +02:00
|
|
|
// Copyright 2014, 2015 by Sascha L. Teichmann
|
2015-03-02 13:14:29 +01:00
|
|
|
// Use of this source code is governed by the MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ipsFromHosts(hosts string) ([]net.IP, error) {
|
|
|
|
|
|
|
|
ips := []net.IP{}
|
|
|
|
|
|
|
|
if len(hosts) == 0 { // Empty list: allow all hosts.
|
|
|
|
return ips, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, host := range strings.Split(hosts, ";") {
|
2015-03-02 13:17:52 +01:00
|
|
|
hips, err := net.LookupIP(host)
|
|
|
|
if err != nil {
|
2015-03-02 13:14:29 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
2015-03-02 13:17:52 +01:00
|
|
|
ips = append(ips, hips...)
|
2015-03-02 13:14:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ips, nil
|
|
|
|
}
|