package
Version:
v0.3.5
Opens a new window with list of versions in this module.
Published: Jan 12, 2026
License: MIT
Opens a new window with license information.
Imports: 2
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
Network (网络)
提供网络相关的实用函数。
API
GetInternalNetworkIp
- 签名:
func GetInternalNetworkIp() string
- 描述: 获取本机在局域网中的 IP 地址。通过建立 UDP 伪连接(不发送数据)来自动选择合适的路由接口 IP。
示例
import (
"fmt"
"github.com/fireflycore/go-utils/network"
)
func main() {
ip := network.GetInternalNetworkIp()
fmt.Println("Local IP:", ip)
}
Documentation
¶
func GetInternalNetworkIp() string
GetInternalNetworkIp 获取本机在局域网中的 IP 地址
原理:通过建立 UDP 伪连接(不发送数据)来自动选择合适的路由接口 IP
返回: 字符串形式的 IP 地址(如 "192.168.1.5")。如果获取失败,返回 "127.0.0.1"
Source Files
¶
Click to show internal directories.
Click to hide internal directories.