From 2d6888cb979222201e1906950669be85d49cb1ae Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 22 Jul 2018 19:51:30 +1000 Subject: [PATCH] Add iplist/cmd/iplist --- iplist/cmd/iplist/main.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 iplist/cmd/iplist/main.go diff --git a/iplist/cmd/iplist/main.go b/iplist/cmd/iplist/main.go new file mode 100644 index 00000000..b46ce215 --- /dev/null +++ b/iplist/cmd/iplist/main.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "log" + "net" + "os" + + "github.com/anacrolix/tagflag" + "github.com/anacrolix/torrent/iplist" +) + +func main() { + var flags = struct { + tagflag.StartPos + Ips []net.IP + }{} + tagflag.Parse(&flags) + il, err := iplist.NewFromReader(os.Stdin) + if err != nil { + log.Fatalf("error loading ip list: %s", err) + } + log.Printf("loaded %d ranges", il.NumRanges()) + for _, ip := range flags.Ips { + r, ok := il.Lookup(ip) + if ok { + fmt.Printf("%s is in %v\n", ip, r) + } else { + fmt.Printf("%s not found\n", ip) + } + } +}