Documentation
¶
Overview ¶
Package ipsource 获取本机公网 IP,支持查询 URL、读取网卡和执行命令三种方式。
Index ¶
Constants ¶
const ( TypeURL = "url" TypeInterface = "netInterface" TypeCommand = "command" )
获取方式
Variables ¶
var DefaultIPv4URLs = []string{
"https://ipv4.ddnspod.com",
"https://api.ipify.org",
"https://ipv4.icanhazip.com",
"https://myip.ipip.net",
}
DefaultIPv4URLs 是默认的 IPv4 查询地址,均为第三方公共服务,用户可在界面修改。
var DefaultIPv6URLs = []string{
"https://ipv6.ddnspod.com",
"https://api6.ipify.org",
"https://ipv6.icanhazip.com",
"https://v6.ident.me",
}
DefaultIPv6URLs 是默认的 IPv6 查询地址。
Functions ¶
func ReplaceRetiredURLs ¶ added in v0.6.5
ReplaceRetiredURLs 把已停止服务的查询地址换成替代地址,替代地址已在列表中时直接去掉旧地址。 返回新列表以及是否有改动。
Types ¶
type InterfaceInfo ¶
InterfaceInfo 是网卡及其地址,供界面选择。
func DemoInterfaces ¶ added in v0.6.8
func DemoInterfaces() []InterfaceInfo
DemoInterfaces 返回演示模式下展示的示例网卡,地址全部取自文档保留地址段。
type Source ¶
type Source struct {
Enable bool `json:"enable"`
Type string `json:"type"`
// URLs 按顺序尝试,直到成功
URLs []string `json:"urls"`
// Interface 为网卡名,Type 为 netInterface 时使用
Interface string `json:"interface"`
// Regex 用于从多个候选地址中筛选,留空取第一个合适的地址
Regex string `json:"regex"`
// Command 通过 sh -c(Windows 为 cmd /C)执行,从输出中提取 IP
Command string `json:"command"`
}
Source 描述一种获取方式。