-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
71 lines (64 loc) · 1.85 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"github.com/securityclippy/ip-rep/helpers/dnshelper"
"github.com/docopt/docopt-go"
"strconv"
"github.com/securityclippy/ip-rep/helpers/filehelper"
)
type IPReport struct {
address string
bad int
good int
}
func CheckIPAddress(ipaddress string, ratelimit int, blacklists []string) (IPReport){
var results IPReport
ch := make(chan string)
rl_chan := make(chan string, ratelimit)
ipaddr := ipaddress
results.address = ipaddr
//note that this particular goroutine is limited by the number of lists in the blacklists variable
//while the ratelimit may be set higher, the ACTUAL ratelimit cannot increase beyond the size of the
//blacklists slice
for i := range blacklists {
bl := blacklists[i]
qr := dnshelper.CreateReverseQuery(ipaddr, bl)
go dnshelper.Txtlookup(qr, ch, rl_chan)
}
for i := 0; i < len(blacklists); i++ {
rep := <- ch
if rep == "true" {
results.bad ++
} else {
results.good ++
}
}
//now check our text based lists that we downloaded...
text_results := filehelper.CheckAgainstTextLists(ipaddress)
results.good += text_results.Good
results.bad += text_results.Bad
return results
}
func main() {
usage := `ip-rep
Usage:
ip-rep -r <file>
--ratelimit <ratelimit>`
args, _ := docopt.Parse(usage, nil, true, "0.1", false)
fn := args["<file>"]
file := fn.(string)
ratelimit := args["<ratelimit>"]
rl := ratelimit.(string)
r, _ := strconv.Atoi(rl)
blacklists := filehelper.GetActiveBlacklists()
//update our text-based blacklists
//filehelper.GetTextBlacklists()
var ipaddresses []string
ipaddresses = filehelper.ReadAddressFile(file)
fmt.Println("Adding "+strconv.Itoa(r/len(blacklists))+" go routines to meet ratelimit")
fmt.Println("scanning "+strconv.Itoa(len(ipaddresses)))
for ip := range ipaddresses {
results := CheckIPAddress(ipaddresses[ip], r, blacklists)
fmt.Println(results)
}
}