Skip to content

Commit

Permalink
Added support for loading patterns from a file
Browse files Browse the repository at this point in the history
  • Loading branch information
James Hannah committed Mar 17, 2015
1 parent d1c9e20 commit 1b6e48b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion ipgrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,31 @@ func ipMatches(target *net.IPNet, queue <-chan linelast, matches chan<- net.IP,

func main() {
verbose := flag.Bool("verbose", false, "Show errors/stuff")
patternsFile := flag.String("patterns", "", "Load search patterns from file")
flag.Parse()
s := make([]chan linelast, 0)
matches := make(chan net.IP)
wait := &sync.WaitGroup{}
for _,i := range flag.Args() {
matchSpecs := make(map[string]bool)
if *patternsFile != "" {
pfile,err := os.Open(*patternsFile)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to read patterns file %s: %s", *patternsFile, err)
os.Exit(1)
}
defer pfile.Close()
lscan := bufio.NewScanner(pfile)
for lscan.Scan() {
line := strings.TrimSpace(lscan.Text())
if !strings.HasPrefix(line, "#") {
matchSpecs[strings.TrimSpace(lscan.Text())] = true
}
}
}
for _,arg := range flag.Args() {
matchSpecs[strings.TrimSpace(arg)] = true
}
for i := range matchSpecs {
m := str2net(i)
if m != nil {
recp := make(chan linelast)
Expand Down

0 comments on commit 1b6e48b

Please sign in to comment.