pikapika/go/main/controller/network.go

25 lines
494 B
Go

package controller
import (
"net"
"strings"
)
// 获取IP的集合
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
}