mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-06-22 21:29:19 +00:00
45 lines
645 B
Go
45 lines
645 B
Go
|
package machine
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
)
|
||
|
|
||
|
func Interfaces() (in []string) {
|
||
|
ifaces, err := net.Interfaces()
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
for _, i := range ifaces {
|
||
|
if i.Flags == net.FlagLoopback {
|
||
|
continue
|
||
|
}
|
||
|
in = append(in, i.Name)
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func LocalIPs() (ips []string) {
|
||
|
ifaces, err := net.Interfaces()
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
for _, i := range ifaces {
|
||
|
if i.Flags == net.FlagLoopback {
|
||
|
continue
|
||
|
}
|
||
|
addrs, err := i.Addrs()
|
||
|
if err != nil {
|
||
|
continue
|
||
|
}
|
||
|
for _, a := range addrs {
|
||
|
ip, _, err := net.ParseCIDR(a.String())
|
||
|
if err != nil {
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
ips = append(ips, ip.String())
|
||
|
}
|
||
|
}
|
||
|
return
|
||
|
}
|