mirror of
https://github.com/sorenisanerd/gotty.git
synced 2024-11-26 13:44:24 +00:00
29 lines
498 B
Go
29 lines
498 B
Go
|
package server
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
)
|
||
|
|
||
|
func listAddresses() (addresses []string) {
|
||
|
ifaces, err := net.Interfaces()
|
||
|
if err != nil {
|
||
|
return []string{}
|
||
|
}
|
||
|
|
||
|
addresses = make([]string, 0, len(ifaces))
|
||
|
|
||
|
for _, iface := range ifaces {
|
||
|
ifAddrs, _ := iface.Addrs()
|
||
|
for _, ifAddr := range ifAddrs {
|
||
|
switch v := ifAddr.(type) {
|
||
|
case *net.IPNet:
|
||
|
addresses = append(addresses, v.IP.String())
|
||
|
case *net.IPAddr:
|
||
|
addresses = append(addresses, v.IP.String())
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return addresses
|
||
|
}
|