mirror of
https://github.com/turbot/steampipe.git
synced 2026-03-03 05:01:01 -05:00
30 lines
510 B
Go
30 lines
510 B
Go
package utils
|
|
|
|
import "net"
|
|
|
|
func LocalAddresses() ([]string, error) {
|
|
addresses := []string{}
|
|
ifaces, err := net.Interfaces()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, i := range ifaces {
|
|
addrs, err := i.Addrs()
|
|
if err != nil {
|
|
continue
|
|
}
|
|
for _, a := range addrs {
|
|
switch v := a.(type) {
|
|
case *net.IPNet:
|
|
isToInclude := v.IP.IsGlobalUnicast() && (v.IP.To4() != nil)
|
|
if isToInclude {
|
|
addresses = append(addresses, v.IP.String())
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return addresses, nil
|
|
}
|