Skip to content

Instantly share code, notes, and snippets.

@fredeil
Last active January 28, 2019 09:49
Show Gist options
  • Save fredeil/6beeba366f75f7349bea118e5257e5e5 to your computer and use it in GitHub Desktop.
Save fredeil/6beeba366f75f7349bea118e5257e5e5 to your computer and use it in GitHub Desktop.
Endlessly spam random bytes over HTTP POST to a server
package main
import (
"math/rand"
"fmt"
"time"
"strings"
"net/http"
)
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
func randData(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}
func main() {
url := "http://192.168.1.123:5000/api/values/1"
fmt.Println("URL:>", url)
// Generate 1GiB of data
data := randData(1024*1024*1024)
req, _ := http.NewRequest("POST", url, strings.NewReader(data))
req.Header.Set("Content-Type", "application/octet-stream")
client := &http.Client{
Timeout: time.Second * 5,
}
for {
client.Do(req)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment