Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertIPv4 ¶ added in v2.0.17
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
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 ¶
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 ¶
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)