From cdaf79f240c1307cb7a2e6290f18938fbfb87207 Mon Sep 17 00:00:00 2001 From: Yavuz <424242424@protonmail.com> Date: Thu, 30 Sep 2021 20:06:59 +0300 Subject: [PATCH] Add inverse options -v --- inscope/main.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/inscope/main.go b/inscope/main.go index 256e58c..abd6899 100644 --- a/inscope/main.go +++ b/inscope/main.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "flag" "errors" "fmt" "io" @@ -17,6 +18,20 @@ type scopeChecker struct { antipatterns []*regexp.Regexp } +func init() { + flag.Usage = func() { + h := []string{ + "Filters in scope and out of scope urls from stdin.", + "", + "Options:", + " -v, --inverse Prints out of scope items", + "", + } + + fmt.Fprintf(os.Stderr, strings.Join(h, "\n")) + } +} + func (s *scopeChecker) inScope(domain string) bool { // if it's a URL pull the hostname out to avoid matching @@ -79,6 +94,11 @@ func newScopeChecker(r io.Reader) (*scopeChecker, error) { } func main() { + var inverse bool + flag.BoolVar(&inverse, "inverse", false, "") + flag.BoolVar(&inverse, "v", false, "") + + flag.Parse() sf, err := openScopefile() if err != nil { @@ -97,10 +117,15 @@ func main() { for sc.Scan() { domain := strings.TrimSpace(sc.Text()) - if checker.inScope(domain) { + inScope := checker.inScope(domain) + if !inverse && inScope { + fmt.Println(domain) + continue + } + + if inverse && !inScope { fmt.Println(domain) } - } }