-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
35 lines (27 loc) · 816 Bytes
/
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
package main
import (
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"regexp"
"time"
)
func main() {
url := "https://free-proxy-list.net/"
client := &http.Client{}
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36")
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
r := regexp.MustCompile(`<tr><td>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})</td><td>(\d+)</td>`)
matches := r.FindAllStringSubmatch(string(body), -1)
rand.Seed(time.Now().UnixNano())
randomIndex := rand.Intn(len(matches))
fmt.Printf("Random proxy: %s:%s\n", matches[randomIndex][1], matches[randomIndex][2])
}