Created
January 25, 2023 19:55
-
-
Save optik-aper/e15664f290866a58acb1254da4653d19 to your computer and use it in GitHub Desktop.
Govultr vm spammer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"encoding/json" | |
"fmt" | |
"time" | |
"github.com/vultr/govultr/v2" | |
"golang.org/x/oauth2" | |
) | |
func main() { | |
vultrClient, ctx := testClient() | |
for i := 0; i < 550; i++ { | |
instCreate(ctx, vultrClient, fmt.Sprintf("inst-spam-%d", i)) | |
time.Sleep(1 * time.Second) | |
} | |
} | |
func prodClient() (*govultr.Client, context.Context) { | |
apiKey := "<YOUR PROD API KEY>" | |
config := &oauth2.Config{} | |
ctx := context.Background() | |
ts := config.TokenSource(ctx, &oauth2.Token{AccessToken: apiKey}) | |
vultrClient := govultr.NewClient(oauth2.NewClient(ctx, ts)) | |
return vultrClient, ctx | |
} | |
func testClient() (*govultr.Client, context.Context) { | |
apiKey := "<YOUR LOCAL API KEY>" | |
config := &oauth2.Config{} | |
ctx := context.Background() | |
ts := config.TokenSource(ctx, &oauth2.Token{AccessToken: apiKey}) | |
vultrClient := govultr.NewClient(oauth2.NewClient(ctx, ts)) | |
vultrClient.SetBaseURL("http://local.api.vultr.com") | |
return vultrClient, ctx | |
} | |
func instCreate(ctx context.Context, client *govultr.Client, label string) { | |
inst, err := client.Instance.Create(ctx, &govultr.InstanceCreateReq{ | |
Region: "ewr", | |
Plan: "vc2-1c-1gb", | |
Label: label, | |
OsID: 1946, | |
Tags: []string{"govultr"}, | |
}) | |
if err != nil { | |
fmt.Println(err) | |
panic(err.Error()) | |
} | |
printJson(inst) | |
} | |
func printJson(output interface{}) { | |
json, err := json.MarshalIndent(output, "", "\t") | |
if err != nil { | |
fmt.Println(err) | |
panic(err.Error()) | |
} | |
fmt.Printf("%s", string(json)) | |
} |
Author
optik-aper
commented
Mar 1, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment