mirror of
https://github.com/siderolabs/talos.git
synced 2025-08-25 00:21:10 +02:00
32 lines
647 B
Go
32 lines
647 B
Go
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
package net
|
|
|
|
import (
|
|
"net"
|
|
)
|
|
|
|
// IPAddrs finds and returns a list of non-loopback IPv4 addresses of the
|
|
// current machine.
|
|
func IPAddrs() (ips []net.IP, err error) {
|
|
ips = []net.IP{}
|
|
|
|
addrs, err := net.InterfaceAddrs()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
for _, a := range addrs {
|
|
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
|
if ipnet.IP.To4() != nil {
|
|
ips = append(ips, ipnet.IP)
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
return ips, nil
|
|
}
|