Skip to content

Commit

Permalink
Merge pull request #184 from projectdiscovery/feat-my-ip
Browse files Browse the repository at this point in the history
Using aws endpoint to retrieve public ip
  • Loading branch information
Mzack9999 authored Jun 21, 2023
2 parents 840d3da + 8647c83 commit c2ae5e0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ip/iputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"strconv"
"strings"
"time"

"github.com/projectdiscovery/utils/consts"
osutil "github.com/projectdiscovery/utils/os"
Expand Down Expand Up @@ -264,9 +265,10 @@ func AsIPV6CIDR(IPV6 string) string {
}

// WhatsMyIP attempts to obtain the external ip through public api
// Copied from https://github.com/projectdiscovery/naabu/blob/master/v2/pkg/scan/externalip.go
func WhatsMyIP() (string, error) {
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "https://api.ipify.org?format=text", nil)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://checkip.amazonaws.com/", nil)
if err != nil {
return "", nil
}
Expand Down

0 comments on commit c2ae5e0

Please sign in to comment.