1 Star 0 Fork 0

danlansky/go-library

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ip.go 373 Bytes
一键复制 编辑 原始数据 按行查看 历史
zhangminghua 提交于 11个月前 . feat:基础工具包
package utils
import (
"net"
)
func GetIp() (ip string) {
ip = "127.0.0.1"
addrs, err := net.InterfaceAddrs()
if err != nil {
return
}
for _, address := range addrs {
// 检查ip地址判断是否回环地址
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return ipnet.IP.String()
}
}
}
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/danlansky/go-library.git
git@gitee.com:danlansky/go-library.git
danlansky
go-library
go-library
v1.0.7

搜索帮助