2021-02-02 12:05:47 +01:00
|
|
|
package geolocate
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
2021-02-03 12:23:15 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/httpx"
|
2022-01-03 13:53:23 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
2021-02-02 12:05:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func ipConfigIPLookup(
|
|
|
|
ctx context.Context,
|
|
|
|
httpClient *http.Client,
|
2022-01-03 13:53:23 +01:00
|
|
|
logger model.Logger,
|
2021-02-02 12:05:47 +01:00
|
|
|
userAgent string,
|
|
|
|
) (string, error) {
|
2022-01-05 14:15:42 +01:00
|
|
|
data, err := (&httpx.APIClientTemplate{
|
2021-02-02 12:05:47 +01:00
|
|
|
BaseURL: "https://ipconfig.io",
|
|
|
|
HTTPClient: httpClient,
|
|
|
|
Logger: logger,
|
|
|
|
UserAgent: httpheader.CLIUserAgent(),
|
2022-01-05 14:15:42 +01:00
|
|
|
}).Build().FetchResource(ctx, "/")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
return DefaultProbeIP, err
|
|
|
|
}
|
|
|
|
ip := strings.Trim(string(data), "\r\n\t ")
|
|
|
|
logger.Debugf("ipconfig: body: %s", ip)
|
|
|
|
return ip, nil
|
|
|
|
}
|