ipKit

package
v2.0.17 Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertIPv4 added in v2.0.17

func AssertIPv4(ipv4 string) error

AssertIPv4

e.g.

("192.168.9.254")	=> nil
("127.0.0.1")	 	=> nil
("localhost")	 	=> test/test1.go:11|main [Assertion failed] ipv4(localhost) is invalid(Key: '' Error:Field validation for '' failed on the 'ipv4' tag)
("::1")	 			=> test/test1.go:12|main [Assertion failed] ipv4(::1) is invalid(Key: '' Error:Field validation for '' failed on the 'ipv4' tag)

func GetLocalIp deprecated

func GetLocalIp() (string, error)

GetLocalIp 获取本机ip

Deprecated: 直接使用 GetOutboundIP()

参考: 系统性能数据gopsutil库 https://topgoer.com/%E5%85%B6%E4%BB%96/%E7%B3%BB%E7%BB%9F%E6%80%A7%E8%83%BD%E6%95%B0%E6%8D%AEgopsutil%E5%BA%93.html

func GetOutboundIP

func GetOutboundIP() (string, error)

GetOutboundIP 通过UDP获取本机ip(Get preferred outbound ip of this machine)

参考: 系统性能数据gopsutil库 https://topgoer.com/%E5%85%B6%E4%BB%96/%E7%B3%BB%E7%BB%9F%E6%80%A7%E8%83%BD%E6%95%B0%E6%8D%AEgopsutil%E5%BA%93.html 通过 UDP 获取本机 IP http://t.zoukankan.com/fousor-p-14874576.html

PS: 由于会申请一个UDP的端口,所以如果经常调用也会比较耗时的,这里如果需要可以将查询到的IP给缓存起来,性能可以获得很大提升.

func GetRegion

func GetRegion(ip string) (string, error)

GetRegion

IP地址查询 - 在线工具(可以查看本机的外网ip): https://tool.lu/ip/

@return 第1个返回值的格式: 国家|区域|省份|城市|ISP

e.g. ("1.1.1.1") => ("澳大利亚|0|0|0|0", nil) ("1.2.3.4") => ("美国|0|华盛顿|0|谷歌", nil) ("10.0.9.141") => ("0|0|0|内网IP|内网IP", nil) ("218.90.174.146") => ("中国|0|江苏省|无锡市|电信", nil)

func IsIP

func IsIP(str string) bool

IsIP 检查传参是否为ip(支持ipv4和ipv6)?

参考:https://www.php.cn/be/go/441401.html

func IsIPv4

func IsIPv4(str string) bool

IsIPv4

"0.0.0.0" => true "127.0.0.1" => true

func IsIPv6

func IsIPv6(str string) bool

Types

type IpInfo

type IpInfo struct {
	Type int
	IP   net.IP
}

func GetIpInfo

func GetIpInfo(str string) IpInfo

GetIpInfo 获取ip字符串的信息.

@param str 字符串,IPv4 或 IPv6

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