ipKit

package
v3.1.112 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// GetInternalIp 获取内部ip.
	/*
		e.g.
		fmt.Println(ipKit.GetInternalIp()) // 172.20.10.4
	*/
	GetInternalIp func() string = netutil.GetInternalIp

	// IsInternalIP 判断ip是否是局域网ip.
	IsInternalIP func(IP net.IP) bool = netutil.IsInternalIP
)
View Source
var (
	// GetPublicIpInfo 获取公网ip信息.
	/*
		PS: 涉及发送http请求, 会有一定的耗时(得考虑内网环境).

		e.g.
		info, err := ipKit.GetPublicIpInfo()
		if err != nil {
			panic(err)
		}
		fmt.Println(jsonKit.MarshalIndentToString(info, "", "    "))

		# Output
		{
		    "status": "success",
		    "country": "China",
		    "countryCode": "CN",
		    "region": "JS",
		    "regionName": "Jiangsu",
		    "city": "Suzhou",
		    "lat": 31.3093,
		    "lon": 120.602,
		    "isp": "Chinanet",
		    "org": "Chinanet JS",
		    "as": "AS4134 CHINANET-BACKBONE",
		    "query": "49.93.33.211"
		} <nil>
	*/
	GetPublicIpInfo func() (*netutil.PublicIpInfo, error) = netutil.GetPublicIpInfo

	// IsPublicIP 判断ip是否是公共ip.
	IsPublicIP func(IP net.IP) bool = netutil.IsPublicIP
)
View Source
var (
	// GetIps 获取ipv4地址列表.
	/*
		e.g.
		fmt.Println(ipKit.GetIps()) // [172.20.10.4 198.18.0.1]
	*/
	GetIps func() []string = netutil.GetIps
)
View Source
var (
	// ParseIPString string => net.IP
	ParseIPString func(s string) net.IP = net.ParseIP
)

Functions

func AssertIP

func AssertIP(ip string) error

func AssertIPv4

func AssertIPv4(ipv4 string) error

Types

type IpInfo

type IpInfo struct {
	Type int
	IP   net.IP
}

func (IpInfo) IsIP

func (info IpInfo) IsIP() bool

func (IpInfo) IsIPv4

func (info IpInfo) IsIPv4() bool

func (IpInfo) IsIPv6

func (info IpInfo) IsIPv6() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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