Skip to content

Instantly share code, notes, and snippets.

@esell
Created January 14, 2022 19:57
Show Gist options
  • Save esell/69bca9c1f25ad56f699b8a1628112213 to your computer and use it in GitHub Desktop.
Save esell/69bca9c1f25ad56f699b8a1628112213 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
"time"
)
var (
storageAcctName = flag.String("s", "blah", "storage account name")
workerCount = flag.Int("w", 1, "worker count")
maxConns = flag.Int("m", 5, "max connections to host")
recordCount = 0
)
func main() {
flag.Parse()
jobs := make(chan string, *workerCount*1000)
tr := &http.Transport{
MaxIdleConns: *maxConns,
MaxIdleConnsPerHost: *maxConns,
}
client := &http.Client{
Timeout: 10 * time.Second,
Transport: tr,
}
doStuff(*storageAcctName + ".blob.core.windows.net", jobs, client)
}
func doStuff(host string, jobs <-chan string, client *http.Client) {
file, err := os.Open("word.list")
if err != nil {
fmt.Println("failed to open")
}
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
var text []string
for scanner.Scan() {
text = append(text, scanner.Text())
}
file.Close()
for _, each_ln := range text {
myerr := getContainer(host, each_ln, client)
if myerr != nil {
fmt.Println(myerr)
}
}
}
func getContainer(host, dir string, client *http.Client) error {
fmt.Printf(".")
resp, err := http.Get("https://" + host + "/" + dir + "?restype=container&comp=list")
if err != nil {
return err
}
// in order to re-use connections we have
// to read the body (https://golang.org/pkg/net/http/#Client.Do)
ioutil.ReadAll(resp.Body)
if resp.StatusCode == 200 {
//winneA
fmt.Println(" ")
fmt.Println("SUCCESS: https://" + host + "/" + dir + "?restype=container&comp=list")
}
resp.Body.Close()
return nil
}
func scanLines(path string, results chan<- string) {
fmt.Println("loading file...")
file, err := os.Open(path)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
blah := scanner.Text()
recordCount++
results <- blah
fmt.Printf(".")
}
close(results)
fmt.Println("file load done")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment