Skip to content

Commit

Permalink
feat(provider): added ip6.me
Browse files Browse the repository at this point in the history
Signed-off-by: Mario-F <github@fritschen.net>
  • Loading branch information
Mario-F committed Mar 8, 2022
1 parent 79f75ec commit 1377333
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions internal/providers/ip6me.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package providers

import (
"io/ioutil"
"net/http"

"github.com/Mario-F/hetzner-dyndns/internal/logger"
"github.com/Mario-F/hetzner-dyndns/internal/network"
)

func ip6meGetIP() (string, error) {
logger.Debugf("Start GetIP with ip6me")

resp, err := http.Get("http://ip6only.me/api/")
if err != nil {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return "", errResponseNotOK
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}

ip, err := captureIPv6(string(body))
if err != nil {
return "", err
}
if ip == "" {
return "", errIPNotFound
}
logger.Debugf("Found IP with ip6me: %+v\n", ip)
return ip, nil
}

var ip6meProvider Provider = Provider{
GetIP: ip6meGetIP,
Version: network.IPv6,
ProviderName: "ip6me",
}

func init() {
ProviderList = append(ProviderList, ip6meProvider)
}

0 comments on commit 1377333

Please sign in to comment.