-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
101 lines (68 loc) · 2.01 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"bufio"
"flag"
"log"
"os"
"sync"
)
type StoreArgs struct {
Concurrency int
Help bool
Input string
Function string
}
func intakeFunction(chanInput chan string, input string) ([]string) {
readFile, err := os.Open(input)
if err != nil {
log.Fatalln(err) // Return the error to the caller
}
defer readFile.Close() // Ensure the file is closed when the function returns
var lines []string // Create a slice to hold the lines
fileScanner := bufio.NewScanner(readFile)
fileScanner.Split(bufio.ScanLines)
for fileScanner.Scan() {
chanInput <- fileScanner.Text() // Append each line to the slice
}
if err := fileScanner.Err(); err != nil {
log.Fatalln(err)
}
return lines // Return the slice containing all the lines
}
func main() {
args := StoreArgs{}
storeCommand := flag.NewFlagSet("main", flag.ContinueOnError)
storeCommand.StringVar(&args.Function, "f", "whois", "What function to run ssl/whois")
storeCommand.IntVar(&args.Concurrency, "c", 100, "How many goroutines running concurrently")
storeCommand.BoolVar(&args.Help, "h", false, "print usage!")
storeCommand.StringVar(&args.Input, "i", "NONE", "A file with IPs/CIDRs or domains on each line")
storeCommand.Parse(os.Args[1:])
inputChannel := make(chan string)
var inputwg sync.WaitGroup
if args.Function == "whois"{
for i := 0; i < args.Concurrency; i++ {
inputwg.Add(1)
go func() {
defer inputwg.Done()
for line := range inputChannel {
getOrg(line)
}
}()
}
} else if args.Function == "ssl"{
for i := 0; i < args.Concurrency; i++ {
inputwg.Add(1)
go func() {
defer inputwg.Done()
for line := range inputChannel {
getOrganizationFromSSL(line)
}
}()
}
} else {
log.Fatalln("You provided invalid function")
}
intakeFunction(inputChannel, args.Input)
close(inputChannel)
inputwg.Wait()
}