Show skipped hosts

This commit is contained in:
Ice3man543
2021-08-17 14:50:54 +05:30
parent 3177aea6f9
commit 586b4c0f8e
2 changed files with 21 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ import (
"strings"
"github.com/bluele/gcache"
"github.com/projectdiscovery/gologger"
)
// Cache is a cache for host based errors. It allows skipping
@@ -16,6 +17,7 @@ import (
// that remain so for a duration.
type Cache struct {
hostMaxErrors int
verbose bool
failedTargets gcache.Cache
}
@@ -29,6 +31,12 @@ func New(hostMaxErrors, maxHostsCount int) *Cache {
return &Cache{failedTargets: gc, hostMaxErrors: hostMaxErrors}
}
// SetVerbose sets the cache to log at verbose level
func (c *Cache) SetVerbose(verbose bool) *Cache {
c.verbose = verbose
return c
}
// Close closes the host errors cache
func (c *Cache) Close() {
c.failedTargets.Purge()
@@ -76,7 +84,18 @@ func (c *Cache) Check(value string) bool {
return false
}
numberOfErrorsValue := numberOfErrors.(int)
return numberOfErrorsValue >= c.hostMaxErrors
if numberOfErrors == -1 {
return true
}
if numberOfErrorsValue >= c.hostMaxErrors {
_ = c.failedTargets.Set(finalValue, -1)
if c.verbose {
gologger.Verbose().Msgf("Skipping %s as it has failed %d times", finalValue, numberOfErrorsValue)
}
return true
}
return false
}
// MarkFailed marks a host as failed previously