Skip to content

Commit

Permalink
bunch of fixes
Browse files Browse the repository at this point in the history
- fix color output
- fix url regex
- adding initial custom transport
  • Loading branch information
ellisonleao committed Mar 7, 2021
1 parent 14568d5 commit d9f8997
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
# binary
vl
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vl:
@go build ./cmd/vl
33 changes: 19 additions & 14 deletions cmd/vl/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/tls"
"flag"
"fmt"
"io/ioutil"
Expand All @@ -14,17 +15,18 @@ import (
)

var (
urlRE = regexp.MustCompile(`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)`)
urlRE = regexp.MustCompile(`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9]{1,6}\b([-a-zA-Z0-9!@:%_\+.~#?&\/\/=]*)`)
skipStatus = flag.String("a", "", "-a 500,400")
timeout = flag.Duration("t", 5*time.Second, "-t 10")
timeout = flag.Duration("t", 5*time.Second, "-t 10s or -t 1h")
whitelist = flag.String("w", "", "-w server1.com,server2.com")
size = flag.Int("s", 50, "-s 50")
)

const (
okColor = "\033[1;34m%s\033[0m\n"
warningColor = "\033[1;33m%s\033[0m\n"
errorColor = "\033[1;31m%s\033[0m\n"
debugColor = "\033[0;36m%s\033[0m\n"
var (
errorColor = "\033[1;31m%d\033[0m"
errorStrColor = "\033[1;31m%s\033[0m"
okColor = "\033[1;32m%d\033[0m"
debugColor = "\033[1;36m%d\033[0m"
)

type response struct {
Expand Down Expand Up @@ -69,18 +71,22 @@ func main() {
matches := urlRE.FindAllString(string(file), -1)
client := &http.Client{
Timeout: *timeout,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
wg := &sync.WaitGroup{}

results := make(chan *response)
requests := make(chan string)

// spawn workers
for i := 0; i <= 50; i++ {
for i := 0; i <= 10; i++ {
wg.Add(1)
go worker(wg, requests, results, client)
}

// producer
go func() {
for _, url := range matches {
if isInStr(url, whitelisted) {
Expand All @@ -91,25 +97,24 @@ func main() {
close(requests)
wg.Wait()
close(results)
fmt.Printf("Found %d URIs\n", len(matches))
}()

for i := range results {
shouldSkipURL := len(skipped) > 0 && isIn(i.Response.StatusCode, skipped)
if i.Err != nil {
fmt.Printf(errorColor, fmt.Sprintf("[ERROR] %s", i.URL))
fmt.Printf("[%s] %s\n", fmt.Sprintf(errorStrColor, "ERROR"), i.URL)
continue
}

statusColor := okColor
if i.Response.StatusCode > 400 {
statusColor = errorColor
} else if shouldSkipURL {
statusColor = debugColor
}

if !shouldSkipURL {
fmt.Printf(statusColor, fmt.Sprintf("[%d] %s", i.Response.StatusCode, i.URL))
} else {
fmt.Printf(debugColor, fmt.Sprintf("[%d] %s", i.Response.StatusCode, i.URL))
}
fmt.Printf("[%s] %s \n", fmt.Sprintf(statusColor, i.Response.StatusCode), i.URL)
}
}

Expand Down

0 comments on commit d9f8997

Please sign in to comment.