netUtil

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NetAddress

func NetAddress() (map[string]map[string]string, error)

NetAddress 获取当前主机的网络接口及其对应的IP地址信息。

返回一个嵌套的 map,其中外层 map 的键为网络接口名称,内层 map 包含以下键值对:

  • "version": IP 版本("IPv4" 或 "IPv6")
  • "ip": IP 地址的字符串表示

如果获取网络接口或地址时发生错误,返回 nil 和对应的错误信息。

示例返回值:

{
  "eth0": {"version": "IPv4", "ip": "192.168.1.100"},
  "lo":   {"version": "IPv4", "ip": "127.0.0.1"}
}

注意:此函数适用于需要获取主机网络信息的场景,如网络配置检查或日志记录。

func OutboundIp

func OutboundIp(targetIp string) (string, error)

OutboundIp 获取本地用于访问指定目标IP的出站IP地址。

参数:

targetIp: 目标IP地址(可选包含端口号,如未指定则默认使用80端口)。

返回值:

string: 本地用于访问目标IP的出站IP地址。
error: 如果连接目标IP失败,返回错误信息。

注意:

  • 如果目标IP未包含端口号,函数会自动添加默认端口80。
  • 使用UDP协议建立连接以获取本地地址。

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL