Skip to content

Commit

Permalink
feat(publicip/http): add ipleak support for all IP versions
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Feb 3, 2024
1 parent 1c76c84 commit 8f2e507
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,14 @@ You can otherwise customize it with the following:
- `ipinfo` using [https://ipinfo.io/ip](https://ipinfo.io/ip)
- `google` using [https://domains.google.com/checkip](https://domains.google.com/checkip)
- `spdyn` using [https://checkip.spdyn.de](https://checkip.spdyn.de/)
- `ipleak` using [https://ipleak.net/json](https://ipleak.net/json)
- You can also specify an HTTPS URL such as `https://ipinfo.io/ip`
- `PUBLICIPV4_HTTP_PROVIDERS` gets your public IPv4 address only. It can be one or more of the following:
- `ipleak` using [https://ipv4.ipleak.net/json](https://ipv4.ipleak.net/json)
- `ipify` using [https://api.ipify.org](https://api.ipify.org)
- You can also specify an HTTPS URL such as `https://ipinfo.io/ip`
- `PUBLICIPV6_HTTP_PROVIDERS` gets your public IPv6 address only. It can be one or more of the following:
- `ipleak` using [https://ipv6.ipleak.net/json](https://ipv6.ipleak.net/json)
- `ipify` using [https://api6.ipify.org](https://api6.ipify.org)
- You can also specify an HTTPS URL such as `https://ipinfo.io/ip`
- `PUBLICIP_DNS_PROVIDERS` gets your public IPv4 address only or IPv6 address only or one of them (see #136). It can be one or more of the following:
Expand Down
14 changes: 12 additions & 2 deletions pkg/publicip/http/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
Ipify Provider = "ipify"
Ipinfo Provider = "ipinfo"
Spdyn Provider = "spdyn"
Ipleak Provider = "ipleak"
)

func ListProviders() []Provider {
Expand All @@ -26,6 +27,7 @@ func ListProviders() []Provider {
Ipify,
Ipinfo,
Spdyn,
Ipleak,
}
}

Expand Down Expand Up @@ -65,13 +67,19 @@ func ValidateProvider(provider Provider, version ipversion.IPVersion) error {
func (provider Provider) url(version ipversion.IPVersion) (url string, ok bool) {
switch version {
case ipversion.IP4:
if provider == Ipify {
switch provider { //nolint:exhaustive
case Ipify:
url = "https://api.ipify.org"
case Ipleak:
url = "https://ipv4.ipleak.net/json"
}

case ipversion.IP6:
if provider == Ipify {
switch provider { //nolint:exhaustive
case Ipify:
url = "https://api6.ipify.org"
case Ipleak:
url = "https://ipv6.ipleak.net/json"
}

case ipversion.IP4or6:
Expand All @@ -86,6 +94,8 @@ func (provider Provider) url(version ipversion.IPVersion) (url string, ok bool)
url = "https://ipinfo.io/ip"
case Spdyn:
url = "https://checkip.spdyn.de"
case Ipleak:
url = "https://ipleak.net/json"
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/publicip/http/providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ func Test_ListProvidersForVersion(t *testing.T) {
}{
"ip4or6": {
version: ipversion.IP4or6,
providers: []Provider{Google, Ifconfig, Ipify, Ipinfo, Spdyn},
providers: []Provider{Google, Ifconfig, Ipify, Ipinfo, Spdyn, Ipleak},
},
"ip4": {
version: ipversion.IP4,
providers: []Provider{Ipify},
providers: []Provider{Ipify, Ipleak},
},
"ip6": {
version: ipversion.IP6,
providers: []Provider{Ipify},
providers: []Provider{Ipify, Ipleak},
},
}

Expand Down

0 comments on commit 8f2e507

Please sign in to comment.