1
0
Fork 0
mirror of https://gitlab.com/pnx-tools/dns-updater.git synced 2026-06-16 05:54:56 +02:00
dns-updater/ip/resolver/ipme/service.go
2023-04-28 16:43:49 +02:00

46 lines
652 B
Go

package ipme
import (
"io"
"net"
"net/http"
"strings"
)
type Service struct {
url string
}
func New() *Service {
return &Service{
url: "https://ip.me",
}
}
func (s Service) Name() string {
return "ip.me"
}
func (s Service) Lookup() (net.IP, error) {
req, err := http.NewRequest("GET", s.url, nil)
if err != nil {
return nil, err
}
req.Header.Add("User-Agent", "curl")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
// Trim spaces and stuff.
ip_str := strings.TrimSpace(string(body))
return net.ParseIP(ip_str), err
}