ipv4类

package
v0.0.0-...-2910145 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package gipv4 提供了用于处理 IPv4 地址的有用 API。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHostByName

func GetHostByName(hostname string) (string, error)

GetHostByName 返回给定互联网主机名对应的IPv4地址。

func GetHostsByName

func GetHostsByName(hostname string) ([]string, error)

GetHostsByName 函数根据给定的互联网主机名返回对应的 IPv4 地址列表。

func GetIntranetIp

func GetIntranetIp() (ip string, err error)

GetIntranetIp 获取并返回当前机器的第一个内网IP地址。

func GetIntranetIpArray

func GetIntranetIpArray() (ips []string, err error)

GetIntranetIpArray 获取并返回当前机器的内网IP列表。

func GetIpArray

func GetIpArray() (ips []string, err error)

GetIpArray 获取并返回当前主机的所有IP地址。

func GetMac

func GetMac() (mac string, err error)

GetMac 获取并返回当前主机的第一个MAC地址。

func GetMacArray

func GetMacArray() (macs []string, err error)

GetMacArray 获取并返回当前主机的所有MAC地址。

func GetNameByAddr

func GetNameByAddr(ipAddress string) (string, error)

GetNameByAddr 根据给定的IP地址返回相应的Internet主机名。

func GetSegment

func GetSegment(ip string) string

GetSegment 返回给定IP地址的段。例如:192.168.2.102 -> 192.168.2

func Ip2long

func Ip2long(ip string) uint32

Ip2long 将IP地址转换为一个uint32整数。

func IsIntranet

func IsIntranet(ip string) bool

IsIntranet 检查并返回给定的IP是否为内网IP。

本地(Local):127.0.0.1 A类:10.0.0.0--10.255.255.255 B类:172.16.0.0--172.31.255.255 C类:192.168.0.0--192.168.255.255

func Long2ip

func Long2ip(long uint32) string

Long2ip 将一个 uint32 类型的整数形式 IP 地址转换为其字符串类型地址。

func MustGetIntranetIp

func MustGetIntranetIp() string

MustGetIntranetIp 的行为与 GetIntranetIp 相同,但当发生任何错误时,它会触发 panic。

func ParseAddress

func ParseAddress(address string) (string, int)

ParseAddress 将 `address` 解析为其 IP 地址和端口号。 例如:192.168.1.1:80 -> 192.168.1.1, 80

func Validate

func Validate(ip string) bool

Validate用于检查给定的`ip`是否为有效的IPv4地址。

Types

This section is empty.

Jump to

Keyboard shortcuts

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