Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding get public ip helper #47

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,15 @@ func init() {

return result, nil
}))
MustAddFunction(NewWithSingleSignature("public_ip",
"() string",
func(args ...interface{}) (interface{}, error) {
publicIP := GetPublicIP()
if publicIP == "" {
return nil, errors.New("could not retrieve public ip")
}
return publicIP, nil
}))

DefaultHelperFunctions = HelperFunctions()
FunctionNames = GetFunctionNames(DefaultHelperFunctions)
Expand Down
1 change: 1 addition & 0 deletions dsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func TestGetPrintableDslFunctionSignatures(t *testing.T) {
mmh3(arg1 interface{}) interface{}
oct_to_dec(arg1 interface{}) interface{}
print_debug(args ...interface{})
public_ip() string
rand_base(length uint, optionalCharSet string) string
rand_char(optionalCharSet string) string
rand_int(optionalMin, optionalMax uint) int
Expand Down
20 changes: 20 additions & 0 deletions public_ip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package dsl

import (
"sync"

iputil "github.com/projectdiscovery/utils/ip"
)

var (
publicIP string
getOnce sync.Once
)

// GetPublicIp of the host
func GetPublicIP() string {
getOnce.Do(func() {
publicIP, _ = iputil.WhatsMyIP()
})
return publicIP
}