Based on the response you provided, the format of the JSON is as follows: {…
- User
Based on the response you provided, the format of the JSON is as follows:
{ “user_agents”: [ “Mozilla/5.0 (Linux; Android 6.0.1; vivo 1610 Build/MMB29M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/100.0.4896.127 Mobile Safari/537.36”, “Mozilla/5.0 (Linux; Android 10; Redmi Note 8 Pro Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/100.0.4896.127 Mobile Safari/537.36 OcIdWebView ({\x22os\x22:\x22Android\x22,\x22osVersion\x22:\x2229\x22,\x22app\x22:\x22com.google.android.gms\x22,\x22appVersion\x22:\x22219\x22,\x22style\x22:2,\x22isDarkTheme\x22:false})”, … ] }
To access the “user_agents” array in the JSON response, you can use the following code:
package main
import ( “encoding/json” “fmt” “log” “net/http” )
type Response struct { UserAgents []string json:"user_agents" }
func getUserAgents() { url := “http://localhost:5000/api/get_ua”
resp, err := http.Get(url) if err != nil { log.Fatal(err) } defer resp.Body.Close() var response Response err = json.NewDecoder(resp.Body).Decode(&response) if err != nil { log.Fatal(err) } for _, ua := range response.UserAgents { fmt.Println(ua) }}
func main() { getUserAgents() }
In this example, I introduced a new Response struct with a field UserAgents of type []string. The json:"user_agents" tag is used to match the field name in the JSON response.
The for loop then iterates over the UserAgents slice and prints each user agent.
Please I wanna store that user_agents responce as an array of strings please, heres an example of my hardcoded one so I dont have to spend time changing the code:
userAgents := []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”, }
- Assistant
If you want to store the user_agents response as an array of strings, you can modify the code as follows:
package main import ( "encoding/json" "fmt" "log" "net/http" ) type Response struct { UserAgents []string `json:"user_agents"` } func getUserAgents() []string { // Replace this with your API endpoint URL url := "http://localhost:5000/api/get_ua" resp, err := http.Get(url) if err != nil { log.Fatal(err) } defer resp.Body.Close() var response Response err = json.NewDecoder(resp.Body).Decode(&response) if err != nil { log.Fatal(err) } return response.UserAgents } func main() { userAgents := getUserAgents() // Hardcoded example user_agents // userAgents := []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", // } for _, ua := range userAgents { fmt.Println(ua) } }You can uncomment the
userAgentsvariable that contains the hardcoded example user_agents and comment out thegetUserAgents()function if you want to use the hardcoded values instead. - User
type UAResponse struct { UserAgents []string json:"user_agents"; };
PS C:\Users\Se1zed\Desktop\folder\serumc2\src\bot\methods> go run HTTP-FLOOD.go
command-line-arguments
.\HTTP-FLOOD.go:13:22: syntax error: unexpected json in struct type; possibly missing semicolon or newline or }
- Assistant
Apologies for the error. It seems there is a missing backtick (
) afterjson:"user_agents"`. The correct struct declaration should be:type UAResponse struct { UserAgents []string `json:"user_agents"` }Here's the updated code:
package main import ( "encoding/json" "fmt" "log" "net/http" ) type UAResponse struct { UserAgents []string `json:"user_agents"` } func getUserAgents() []string { // Replace this with your API endpoint URL url := "http://localhost:5000/api/get_ua" resp, err := http.Get(url) if err != nil { log.Fatal(err) } defer resp.Body.Close() var response UAResponse err = json.NewDecoder(resp.Body).Decode(&response) if err != nil { log.Fatal(err) } return response.UserAgents } func main() { userAgents := getUserAgents() // Hardcoded example user_agents // userAgents := []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", // } for _, ua := range userAgents { fmt.Println(ua) } }You can uncomment the
userAgentsvariable that contains the hardcoded example user_agents and comment out thegetUserAgents()function if you want to use the hardcoded values instead.