Update callback calling place

- Callback for every result, even it contains error
- User can handle it using Result.Err
This commit is contained in:
shubhamrasal 2023-05-19 17:27:29 +05:30
parent addddf1e1b
commit bc7ac8d073
3 changed files with 23 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"fmt"
"log"
"github.com/projectdiscovery/goflags"
@ -14,8 +15,16 @@ func main() {
options := runner.Options{
Methods: "GET",
InputTargetHost: goflags.StringSlice{"scanme.sh", "projectdiscovery.io"},
InputTargetHost: goflags.StringSlice{"scanme.sh", "projectdiscovery.io", "localhost"},
//InputFile: "./targetDomains.txt", // path to file containing the target domains list
OnResult: func(r runner.Result) {
// handle error
if r.Err != nil {
fmt.Printf("[Err] %s: %s\n", r.Input, r.Err)
return
}
fmt.Printf("%s %s %d\n", r.Input, r.Host, r.StatusCode)
},
}
if err := options.ValidateOptions(); err != nil {

View File

@ -262,11 +262,12 @@ type Options struct {
ListDSLVariable bool
OutputFilterCondition string
OutputMatchCondition string
OnResult OnResultCallback
DisableUpdateCheck bool
NoDecode bool
Screenshot bool
UseInstalledChrome bool
//The OnResult callback function is invoked for each result. It is important to check for errors in the result before using Result.Err.
OnResult OnResultCallback
DisableUpdateCheck bool
NoDecode bool
Screenshot bool
UseInstalledChrome bool
}
// ParseOptions parses the command line options for application

View File

@ -663,6 +663,13 @@ func (r *Runner) RunEnumeration() {
}
for resp := range output {
// call the callback function if any
// be careful and check for result.Err
if r.options.OnResult != nil {
r.options.OnResult(resp)
}
if resp.Err != nil {
// Change the error message if any port value passed explicitly
if url, err := r.parseURL(resp.URL); err == nil && url.Port() != "" {