4eeadd06a5
* refactor: move more commands to internal/cmd Part of https://github.com/ooni/probe/issues/1335. We would like all commands to be at the same level of engine rather than inside engine (now that we can do it). * fix: update .gitignore * refactor: also move jafar outside engine * We should be good now?
31 lines
641 B
Go
31 lines
641 B
Go
package geolocate
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
|
|
"github.com/ooni/probe-cli/v3/internal/engine/httpx"
|
|
)
|
|
|
|
func ipConfigIPLookup(
|
|
ctx context.Context,
|
|
httpClient *http.Client,
|
|
logger Logger,
|
|
userAgent string,
|
|
) (string, error) {
|
|
data, err := (httpx.Client{
|
|
BaseURL: "https://ipconfig.io",
|
|
HTTPClient: httpClient,
|
|
Logger: logger,
|
|
UserAgent: httpheader.CLIUserAgent(),
|
|
}).FetchResource(ctx, "/")
|
|
if err != nil {
|
|
return DefaultProbeIP, err
|
|
}
|
|
ip := strings.Trim(string(data), "\r\n\t ")
|
|
logger.Debugf("ipconfig: body: %s", ip)
|
|
return ip, nil
|
|
}
|