forked from rmada/tsunami
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser_agent.go
43 lines (39 loc) · 853 Bytes
/
user_agent.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
package main
import (
"bufio"
"fmt"
"log"
"math/rand"
"os"
"time"
)
var (
userAgents []string
random *rand.Rand
source rand.Source
)
func loadUserAgents() {
//Load user agents from file
file, err := os.Open(*userAgentFile)
if err != nil {
//File not found, or whatever, use default UA
userAgents = append(userAgents, "Tsunami Flooder (https://github.com/ammar/tsunami)")
fmt.Println(err)
} else {
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
userAgents = append(userAgents, scanner.Text())
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}
//Initiate random number generator
source = rand.NewSource(time.Now().UnixNano())
random = rand.New(source)
}
func getRandomUserAgent() string {
index := int(random.Uint32()) % len(userAgents)
return userAgents[index]
}