openvpn-mgt/vpnlist.go

72 lines
1.3 KiB
Go
Raw Normal View History

2019-07-30 14:34:12 +00:00
package main
// get https://www.expressvpn.com/vpn-server
// remove everyting starting with >
// remove until "Not supported" and after What the green checks mean
import (
"bufio"
"fmt"
"net"
"net/http"
"strings"
"time"
)
func getServerList(url string) []string {
ret := []string{}
// Create HTTP client with timeout
client := &http.Client{
Timeout: 30 * time.Second,
}
// Make request
response, err := client.Get(url)
if err != nil {
fmt.Println(err)
return nil
}
defer response.Body.Close()
buf := bufio.NewReader(bufio.NewReader(response.Body))
start := false
for {
line, err := buf.ReadString('\n')
if err != nil {
break
}
line = strings.Trim(line, "\n\r ")
if strings.HasPrefix(line, "<") {
continue
}
if line == "Not supported" {
start = true
continue
}
if line == "What the green checks mean" {
start = false
}
if !start {
continue
}
if line == "" {
continue
}
// france-paris-1-ca-version-2.expressnetw.com
line = strings.ToLower(line)
line = strings.ReplaceAll(line, " &amp; ", "")
line = strings.ReplaceAll(line, " ", "")
name := fmt.Sprintf("%s-ca-version-2.expressnetw.com", line)
fmt.Println(name)
if _, err := net.ResolveIPAddr("ip4", name); err == nil {
ret = append(ret, name)
}
}
return ret
}