Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"mime/multipart"
"net/http"
_ "net/http/pprof"
Expand Down Expand Up @@ -295,21 +296,32 @@ func cmdRegisterEstuary(ctx *cli.Context) error {
}

// Get public IP address

publicIPRes, err := http.Get("http://ip-api.com/json")
if err != nil {
return fmt.Errorf("could not get public ip: %v", err)
}
defer publicIPRes.Body.Close()

var ipInfo struct {
Query string
}

if err := json.NewDecoder(publicIPRes.Body).Decode(&ipInfo); err != nil {
return fmt.Errorf("could not get public ip: %v", err)
publicIP, err := http.Get("https://ip2location.io/ip")
if err == nil {
defer publicIP.Body.Close()
bodyBytes, err := io.ReadAll(publicIP.Body)

if err == nil {
bodyStr := string(bodyBytes[:])
ipInfo.Query = bodyStr
}
}

if ipInfo.Query == "" {
publicIPRes, err := http.Get("http://ip-api.com/json")
if err != nil {
return fmt.Errorf("could not get public ip: %v", err)
}
defer publicIPRes.Body.Close()

if err := json.NewDecoder(publicIPRes.Body).Decode(&ipInfo); err != nil {
return fmt.Errorf("could not get public ip: %v", err)
}
}
fmt.Printf("Using IP: %s\n", ipInfo.Query)

// Get peer key
Expand Down