pikapika/go/main/controller/network.go

25 lines
494 B
Go
Raw Normal View History

2021-09-29 23:57:09 +00:00
package controller
import (
"net"
"strings"
)
2021-10-19 10:26:12 +00:00
// 获取IP的集合
2021-09-29 23:57:09 +00:00
func clientIpSet() (string, error) {
address, err := net.InterfaceAddrs()
if err != nil {
return "", err
}
ipSet := make([]string, 0)
for _, address := range address {
// 检查ip地址判断是否回环地址
if ipNet, ok := address.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {
if ipNet.IP.To4() != nil {
ipSet = append(ipSet, ipNet.IP.To4().String())
}
}
}
return strings.Join(ipSet, ","), nil
}