mongo-replica-initializer/network.go

22 lines
435 B
Go
Raw Permalink Normal View History

package main
import (
"net"
)
func GetLocalIPs() ([]net.IP, error) {
var ips []net.IP
addresses, err := net.InterfaceAddrs()
if err != nil {
return nil, err
}
for _, addr := range addresses {
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
ips = append(ips, ipnet.IP)
}
}
}
return ips, nil
}