pikapika/go/pikapi/controller/network.go

24 lines
473 B
Go
Raw Normal View History

2021-09-29 23:57:09 +00:00
package controller
import (
"net"
"strings"
)
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
}