/
nntime.go
58 lines (52 loc) · 1.47 KB
/
nntime.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 sources
import (
"context"
"fmt"
"net/http"
"regexp"
"strings"
"time"
"github.com/nfx/slrp/pmux"
)
var nntimePages = 10
var nntimePattern = "http://nntime.com/proxy-updated-%02d.htm"
func init() {
Sources = append(Sources, Source{
ID: 4,
Homepage: "http://nntime.com",
Frequency: 6 * time.Hour,
Feed: newNetTimeNew,
})
}
func newNetTimeNew(ctx context.Context, h *http.Client) Src {
m := merged()
for i := 1; i <= nntimePages; i++ {
m = m.refresh(newNetTimePage(ctx, h, i))
}
return m
}
func newNetTimePage(ctx context.Context, h *http.Client, i int) func() ([]pmux.Proxy, error) {
var mangedIPs = regexp.MustCompile(`(?m)>(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*\":\"\+(.*)\)`)
var mangles = regexp.MustCompile(`(?m)(?P<char>\w)=(?P<digit>\d);`)
return func() (found []pmux.Proxy, err error) {
body, _, err := req{URL: fmt.Sprintf(nntimePattern, i)}.Do(ctx, h)
if err != nil {
return
}
deMangle := map[string]string{}
for _, perPageContext := range mangles.FindAllStringSubmatch(string(body), -1) {
char, digit := perPageContext[1], perPageContext[2]
deMangle[char] = digit
}
for _, mangledProxy := range mangedIPs.FindAllStringSubmatch(string(body), -1) {
ip := mangledProxy[1]
port := mangledProxy[2]
for k, v := range deMangle {
port = strings.ReplaceAll(port, k, v)
}
port = strings.ReplaceAll(port, "+", "")
found = append(found, pmux.HttpProxy(fmt.Sprintf("%s:%s", ip, port)))
}
return
}
}