-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
87 lines (70 loc) · 2.33 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"bufio"
"github.com/alexflint/go-arg"
"github.com/kangoo13/proxy-checker/core"
"log"
"os"
"strings"
"time"
)
func main() {
var inputArgs = InputArgs{}
p := arg.MustParse(&inputArgs)
if inputArgs.CloudFlareBypass && inputArgs.WebsiteCloudFlare == "" {
p.Fail("If you wish to test bypass cloudflare, please provide website to test against protected by cloudflare with -w")
}
outputFile := OpenFile(inputArgs.GoodProxiesPath)
defer outputFile.Close()
workingProxies := core.CheckProxies(&core.ProxyChecker{
ProxyList: FileToStringSlice(inputArgs.ProxyList),
TimeoutProxy: time.Duration(inputArgs.TimeoutProxy) * time.Second,
AvailableCheckers: core.AvailableCheckers{
CloudFlareBypass: inputArgs.CloudFlareBypass,
Basic: true,
},
WebsiteCloudFlare: inputArgs.WebsiteCloudFlare,
})
datawriter := bufio.NewWriter(outputFile)
defer datawriter.Flush()
for _, data := range workingProxies {
_, _ = datawriter.WriteString(data + "\n")
}
}
func OpenFile(filePath string) *os.File {
f, err := os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, os.ModeAppend|0660)
if err != nil {
log.Fatalf("[OpenFile] error while opening file %s", err)
}
return f
}
func FileToStringSlice(filePath string) []string {
var (
fileTextLines []string
)
readFile, err := os.Open(filePath)
if err != nil {
log.Fatalf("failed to open file: %s", err)
}
defer readFile.Close()
fileScanner := bufio.NewScanner(readFile)
fileScanner.Split(bufio.ScanLines)
for fileScanner.Scan() {
newLine := fileScanner.Text()
if strings.Trim(newLine, "\n\t\r") != "" {
fileTextLines = append(fileTextLines, fileScanner.Text())
}
}
return fileTextLines
}
type InputArgs struct {
ProxyList string `arg:"positional,required" help:"path to the proxyList"`
GoodProxiesPath string `arg:"positional" default:"good_proxies.txt" help:"path to the good proxies identified"`
TimeoutProxy int64 `arg:"-t" default:"4" help:"timeout proxy duration in seconds"`
availableCheckers
WebsiteCloudFlare string `arg:"-w" help:"website to test proxy against cloudflare, needed if -cf"`
}
type availableCheckers struct {
CloudFlareBypass bool `arg:"-c" help:"if activated, check if proxy bypass cloudflare"`
Basic bool `arg:"-b" default:"true" help:"if activated, simply checks if proxy is working"`
}