eth

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultInterface

func GetDefaultInterface() (*net.Interface, error)

GetDefaultInterface 获取当前系统用于连接默认路由的网络接口 该方法通过创建一个虚拟的UDP连接(目标为公共DNS服务器),利用系统路由表确定默认出口网卡 返回: 成功返回网络接口指针,失败返回错误信息

Types

type Eth

type Eth struct {
	Info []Info `json:"info"` // Info 字段是一个 Info 类型的切片,用于存储网卡信息列表。
	Err  error  `json:"err"`  // Err 字段用于存储在获取网卡信息过程中可能发生的错误。
}

Eth 结构体用于封装网卡信息和错误信息。 它包含两个字段:网卡信息列表和错误信息。

func NewEth

func NewEth() *Eth

NewEth 创建并返回一个新的 Eth 实例。 该函数不接受任何参数。 返回值是一个指向 Eth 类型的指针,表示新创建的 Eth 实例。

func (*Eth) GetEthDNS

func (e *Eth) GetEthDNS(eth string) ([]net.IP, error)

GetEthDNS 获取指定网卡的DNS配置

func (*Eth) GetEthGateway

func (e *Eth) GetEthGateway(eth string, ip net.IP) (net.IP, error)

GetEthGateway 根据指定的以太网接口和IP地址获取网关地址。 参数:

eth: 以太网接口名称,例如 "eth0"。
ip: 网络接口的IP地址。

返回值:

net.IP: 网关的IP地址。
error: 如果获取网关地址时发生错误,则返回该错误。

func (*Eth) GetEthInfo

func (e *Eth) GetEthInfo(eth string) (*Info, error)

GetEthInfo 获取指定网卡的网卡信息

func (*Eth) GetEthList

func (e *Eth) GetEthList() []string

GetEthList 获取当前系统中所有正在使用的网络接口名称列表。 该函数通过查询系统中的网络接口信息,筛选出所有处于激活状态(即接口标志中包含FlagUp)的网络接口, 并将其名称添加到一个字符串列表中,最后返回该列表。 如果在获取网络接口信息时发生错误,函数将直接返回nil。

func (*Eth) GetEthListInfo

func (e *Eth) GetEthListInfo()

GetEthListInfo 获取所有网卡的信息 该函数通过调用 GetEthList 和 GetEthInfo 方法获取所有网卡的信息。 通过 Info 字段记录所有网卡的信息。

type Info

type Info struct {
	Name    string   `json:"name" `   // 网卡名称,例如 eth0
	Mac     string   `json:"mac"`     // 网卡mac,例如 00:00:00:00:00:00
	Ip      net.IP   `json:"ip"`      // 网卡ip, 例如 192.168.1.1
	Gw      net.IP   `json:"gw"`      // 网关, 例如 192.168.1.1
	Sub     net.IP   `json:"sub"`     // 网段, 例如 192.168.1.0
	Mask    net.IP   `json:"mask"`    // 网卡掩码, 例如 255.255.255.0
	MaskInt int      `json:"maskInt"` // 网卡掩码, 例如 24
	DnsList []net.IP `json:"dnsList"` // DNS列表
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳