-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecounter.go
84 lines (63 loc) · 2.33 KB
/
ecounter.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
package main
import (
"flag"
"fmt"
"strings"
"time"
)
const emailRegex string = `([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)`
const shaRegex string = `[A-Fa-f0-9]{64}`
const dninieRegex string = `[A-z]?\d{7,8}[TRWAGMYFPDXBNJZSQVHLCKEtrwagmyfpdxbnjzsqvhlcke]`
const urlsRegex string = `https?://([\da-z\.-]+)\.([a-z\.]{2,6})([/\w \.-]*)*/?`
var debug *bool
func main() {
defer timeTrack(time.Now(), "main")
help := flag.Bool("help", false, "Display help")
inputFile := flag.String("input", "test.txt", "File to do the operations")
countIt := flag.String("count", "emails", "What to count")
outputFile := flag.String("output", "output.txt", "File to output the results")
debug = flag.Bool("debug", false, "Debug the script")
encrypt := flag.Bool("encrypt", false, "Encrypts the emails as sha256")
flag.Parse()
if *help == true {
helpMe()
} else {
fileToHandle := fileToString(*inputFile)
var allMatches []string
var allMatchesLC []string
var allMatchesUC []string
var uniques []string
switch *countIt {
case "emails":
allMatches = searchInString(fileToHandle, emailRegex)
allMatchesLC = arrayToLowercase(allMatches)
uniques = uniquesInArray(allMatchesLC)
case "sha256":
allMatches = searchInString(fileToHandle, shaRegex)
allMatchesLC = arrayToLowercase(allMatches)
uniques = uniquesInArray(allMatchesLC)
case "urls":
allMatches = searchInString(fileToHandle, urlsRegex)
uniques = uniquesInArray(allMatches)
case "dnis":
allMatches = searchInString(fileToHandle, dninieRegex)
allMatchesUC = arrayToUpercase(allMatches)
uniques = uniquesInArray(allMatchesUC)
default:
allMatches = searchInString(fileToHandle, emailRegex)
allMatchesLC = arrayToLowercase(allMatches)
uniques = uniquesInArray(allMatchesLC)
}
if *encrypt == true {
uniques = arrayToSha256(uniques)
}
stringFinal := strings.Join(uniques, "\n")
stringToFile(*outputFile, stringFinal)
fmt.Println("\nWHAT HAPPENED?")
fmt.Println("The parsed file : ", *inputFile)
fmt.Println("Number of total", *countIt, "found in", *inputFile, ":", len(allMatches))
fmt.Println("Number of unique", *countIt, "saved in the file", *outputFile, ":", len(uniques))
fmt.Println("The results are hashed as sha256 ?", *encrypt)
fmt.Printf("\n")
}
}