Skip to content

Commit

Permalink
Merge pull request projectdiscovery#210 from projectdiscovery/198-fea…
Browse files Browse the repository at this point in the history
…ture-on-result-callback

Adding on result callback function
  • Loading branch information
ehsandeep authored Sep 26, 2021
2 parents 69d4021 + b480831 commit 7506971
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions v2/pkg/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ type Options struct {
ScanAllIPS bool // Scan all the ips
ScanType string // Scan Type
config *ConfigFile
OnResult OnResultCallback // OnResult callback
}

// OnResultCallback (hostname, ip, ports)
type OnResultCallback func(string, string, []int)

// ParseOptions parses the command line flags provided by a user
func ParseOptions() *Options {
options := &Options{}
Expand Down
4 changes: 4 additions & 0 deletions v2/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ func (r *Runner) handleOutput() {
gologger.Error().Msgf("Could not write results to file %s for %s: %s\n", output, host, err)
}
}

if r.options.OnResult != nil {
r.options.OnResult(host, hostIP, mapKeysToSliceInt(ports))
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions v2/pkg/runner/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ func (r *Runner) host2ips(target string) (targetIPs []string, err error) {
func isOSSupported() bool {
return runtime.GOOS == "linux" || runtime.GOOS == "darwin"
}

func mapKeysToSliceInt(m map[int]struct{}) (s []int) {
for k := range m {
s = append(s, k)
}
return
}

0 comments on commit 7506971

Please sign in to comment.