代码拉取完成,页面将自动刷新
package gotool
import "net"
// Ipv4sLocal 获取本地ipv4地址
func Ipv4sLocal() ([]string, error) {
res := make([]string, 0)
// 获取所有网卡地址
address, err := net.InterfaceAddrs()
if err != nil {
return nil, err
}
// 遍历网卡地址
for _, addr := range address {
// 获取ip地址
ip := addr.(*net.IPNet).IP
// 过滤ip地址
// 127.0.0.0 - 127.255.255.255
// 169.254.0.0 - 169.254.255.255
// 169.254.0.0 - 169.254.255.255
if ip.IsLoopback() || ip.IsLinkLocalMulticast() || ip.IsLinkLocalUnicast() {
continue
}
// 过滤ipv6地址
if ip.To4() != nil {
res = append(res, ip.String())
}
}
return res, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。