-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproviders.go
58 lines (44 loc) · 1.37 KB
/
providers.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
package soxy
import (
"regexp"
"strings"
"sync"
)
// Providers maps the colloqial names of proxy providers to the function that returns their proxies.
var Providers = map[string]func() []Proxy{
"freeproxylists": FreeProxyLists,
}
// FreeProxyLists returns all the HTTP proxies that it can find on the http://www.freeproxylists.com/ website.
func FreeProxyLists() (proxies []Proxy) {
initialLinks := FindLinks("http://www.freeproxylists.com/socks.html", `^socks #\d+`)
links := []string{}
// Vomit, proxy regex
proxyRegex := regexp.MustCompile(`<td>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}<\/td><td>\d+<\/td>`)
// End Vomit
for _, link := range initialLinks {
parsedLink := "http://freeproxylists.com/load_socks_" + link[6:]
links = append(links, parsedLink)
}
var wg sync.WaitGroup
for _, link := range links {
wg.Add(1)
go func(l string) {
defer wg.Done()
doc, err := GetURL(l)
if err != nil {
return
}
matches := proxyRegex.FindAllString(doc, -1)
for i := range matches {
proxies = append(
proxies,
NewProxy(
matches[i][strings.Index(matches[i], "<td>") + len("<td>"):strings.Index(matches[i], "</td>")],
matches[i][strings.LastIndex(matches[i], "<td>") + len("<td>"):strings.LastIndex(matches[i], "</td>")],
))
}
}(link)
}
wg.Wait()
return proxies
}