Skip to content
Open
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
29 changes: 27 additions & 2 deletions inscope/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"flag"
"errors"
"fmt"
"io"
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}

}
}

Expand Down