feat(publicip): add changeip ipv4v6 echo service

This commit is contained in:
Quentin McGaw
2024-06-15 10:24:17 +00:00
parent 3494cfbcbb
commit 2f2bef3d6c
5 changed files with 16 additions and 6 deletions

View File

@@ -290,6 +290,7 @@ You can otherwise customize it with the following:
- `nnev` using [https://ip.nnev.de](https://ip.nnev.de)
- `wtfismyip` using [https://wtfismyip.com/text](https://wtfismyip.com/text)
- `seeip` using [https://api.seeip.org](https://api.seeip.org)
- `changeip` using [https://ip.changeip.com](https://ip.changeip.com)
- You can also specify an HTTPS URL with prefix `url:` for example `url: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)

View File

@@ -26,6 +26,7 @@ func IPv6(text string) (addresses []netip.Addr) {
}
func extract(text string, alphabet string) (addresses []netip.Addr) {
addressesSeen := make(map[netip.Addr]struct{})
var start, end int
for {
for i := start; i < len(text); i++ {
@@ -39,7 +40,11 @@ func extract(text string, alphabet string) (addresses []netip.Addr) {
possibleIPString := text[start:end]
ipAddress, err := netip.ParseAddr(possibleIPString)
if err == nil { // Valid IP address found
addresses = append(addresses, ipAddress)
_, seen := addressesSeen[ipAddress]
if !seen {
addressesSeen[ipAddress] = struct{}{}
addresses = append(addresses, ipAddress)
}
}
if end == len(text) {

View File

@@ -85,14 +85,14 @@ func Test_fetch(t *testing.T) {
ctx: context.Background(),
url: "https://opendns.com/ip",
version: ipversion.IP4or6,
httpContent: []byte(`1.67.201.251 1.67.201.251`),
httpContent: []byte(`1.67.201.251 1.67.201.252`),
err: errors.New("too many IP addresses: found 2 IPv4 addresses instead of 1"),
},
"too many IPv6s for IP4or6": {
ctx: context.Background(),
url: "https://opendns.com/ip",
version: ipversion.IP4or6,
httpContent: []byte(`::1 ::1`),
httpContent: []byte(`::1 ::2`),
err: errors.New("too many IP addresses: found 2 IPv6 addresses instead of 1"),
},
"no IP for IP4": {
@@ -113,7 +113,7 @@ func Test_fetch(t *testing.T) {
ctx: context.Background(),
url: "https://opendns.com/ip",
version: ipversion.IP4,
httpContent: []byte(`1.67.201.251 1.67.201.251`),
httpContent: []byte(`1.67.201.251 1.67.201.252`),
err: errors.New("too many IP addresses: found 2 IPv4 addresses instead of 1"),
},
"no IP for IP6": {
@@ -137,7 +137,7 @@ func Test_fetch(t *testing.T) {
ctx: context.Background(),
url: "https://opendns.com/ip",
version: ipversion.IP6,
httpContent: []byte(`::1 ::1`),
httpContent: []byte(`::1 ::2`),
err: errors.New("too many IP addresses: found 2 IPv6 addresses instead of 1"),
},
}

View File

@@ -23,6 +23,7 @@ const (
Nnev Provider = "nnev"
Wtfismyip Provider = "wtfismyip"
Seeip Provider = "seeip"
Changeip Provider = "changeip"
)
func ListProviders() []Provider {
@@ -38,6 +39,7 @@ func ListProviders() []Provider {
Nnev,
Wtfismyip,
Seeip,
Changeip,
}
}
@@ -136,6 +138,8 @@ func (provider Provider) url(version ipversion.IPVersion) (url string, ok bool)
url = "https://wtfismyip.com/text"
case Seeip:
url = "https://api.seeip.org"
case Changeip:
url = "https://ip.changeip.com"
}
}

View File

@@ -20,7 +20,7 @@ func Test_ListProvidersForVersion(t *testing.T) {
"ip4or6": {
version: ipversion.IP4or6,
providers: []Provider{Google, Ifconfig, Ipify, Ipinfo, Spdyn, Ipleak,
Icanhazip, Ident, Nnev, Wtfismyip, Seeip},
Icanhazip, Ident, Nnev, Wtfismyip, Seeip, Changeip},
},
"ip4": {
version: ipversion.IP4,