-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeonode.go
48 lines (39 loc) · 1.12 KB
/
geonode.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
package ipscraper
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
)
// Does not seem to provide good results at the moment, but the site reports an ongoing issue.
type GeonodeList struct{}
func NewGeonodeList() *GeonodeList {
return &GeonodeList{}
}
type Response struct {
Data []struct {
Ip string `json:"ip"`
Port string `json:"port"`
Protocols []string `json:"protocols"`
} `json:"data"`
}
func (f *GeonodeList) Get() ([]string, error) {
resp, err := http.Get("https://proxylist.geonode.com/api/proxy-list?limit=100&page=1&sort_by=lastChecked&sort_type=desc") // 100 could be enough? The result is normally smaller.
if err != nil {
return nil, fmt.Errorf("http get: %w", err)
}
body, err := ioutil.ReadAll(resp.Body)
var result Response
if err := json.Unmarshal(body, &result); err != nil {
fmt.Println("Can not unmarshal JSON")
}
var ips []string
for _, rec := range result.Data {
if len(rec.Protocols) > 0 && strings.HasPrefix(rec.Protocols[0], "http") {
var url = rec.Protocols[0] + "://" + rec.Ip + ":" + rec.Port
ips = append(ips, url)
}
}
return ips, nil
}