Add iplist/cmd/iplist

This commit is contained in:
Matt Joiner 2018-07-22 19:51:30 +10:00
parent 3a7152ca21
commit 2d6888cb97
1 changed files with 32 additions and 0 deletions

32
iplist/cmd/iplist/main.go Normal file
View File

@ -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)
}
}
}