Add multi hop regions and ips for Surfshark
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"sort"
|
||||
@@ -23,36 +24,34 @@ func _main() int {
|
||||
provider := flag.String("provider", "surfshark", "VPN provider to parse openvpn files for, can be 'surfshark'")
|
||||
flag.Parse()
|
||||
|
||||
var url string
|
||||
var urls []string
|
||||
var suffix string
|
||||
switch *provider {
|
||||
case "surfshark":
|
||||
url = "https://account.surfshark.com/api/v1/server/configurations"
|
||||
urls = []string{
|
||||
"https://account.surfshark.com/api/v1/server/configurations",
|
||||
"https://v2uploads.zopim.io/p/2/L/p2LbwLkvfQoSdzOl6VEltzQA6StiZqrs/12500634259669c77012765139bcfe4f4c90db1e.zip",
|
||||
}
|
||||
suffix = ".prod.surfshark.com"
|
||||
default:
|
||||
fmt.Printf("Provider %q is not supported\n", *provider)
|
||||
return 1
|
||||
}
|
||||
client := network.NewClient(time.Second)
|
||||
zipBytes, status, err := client.GetContent(url)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return 1
|
||||
} else if status != http.StatusOK {
|
||||
fmt.Printf("Getting %s results in HTTP status code %d\n", url, status)
|
||||
return 1
|
||||
}
|
||||
contents, err := zipExtractAll(zipBytes)
|
||||
contents, err := fetchAndExtractFiles(urls...)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return 1
|
||||
}
|
||||
|
||||
uniqueSubdomains := make(map[string]struct{})
|
||||
for _, content := range contents {
|
||||
subdomain, err := extractInformation(content)
|
||||
subdomain, err := extractInformation(content, suffix)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return 1
|
||||
} else if len(subdomain) > 0 {
|
||||
uniqueSubdomains[subdomain] = struct{}{}
|
||||
}
|
||||
uniqueSubdomains[subdomain] = struct{}{}
|
||||
}
|
||||
subdomains := make([]string, len(uniqueSubdomains))
|
||||
i := 0
|
||||
@@ -67,6 +66,24 @@ func _main() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func fetchAndExtractFiles(urls ...string) (contents [][]byte, err error) {
|
||||
client := network.NewClient(10 * time.Second)
|
||||
for _, url := range urls {
|
||||
zipBytes, status, err := client.GetContent(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if status != http.StatusOK {
|
||||
return nil, fmt.Errorf("Getting %s results in HTTP status code %d", url, status)
|
||||
}
|
||||
newContents, err := zipExtractAll(zipBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
contents = append(contents, newContents...)
|
||||
}
|
||||
return contents, nil
|
||||
}
|
||||
|
||||
func zipExtractAll(zipBytes []byte) (contents [][]byte, err error) {
|
||||
r, err := zip.NewReader(bytes.NewReader(zipBytes), int64(len(zipBytes)))
|
||||
if err != nil {
|
||||
@@ -90,7 +107,7 @@ func zipExtractAll(zipBytes []byte) (contents [][]byte, err error) {
|
||||
return contents, nil
|
||||
}
|
||||
|
||||
func extractInformation(content []byte) (subdomain string, err error) {
|
||||
func extractInformation(content []byte, suffix string) (subdomain string, err error) {
|
||||
lines := strings.Split(string(content), "\n")
|
||||
for _, line := range lines {
|
||||
if strings.HasPrefix(line, "remote ") {
|
||||
@@ -99,7 +116,10 @@ func extractInformation(content []byte) (subdomain string, err error) {
|
||||
return "", fmt.Errorf("not enough words on line %q", line)
|
||||
}
|
||||
host := words[1]
|
||||
return strings.TrimSuffix(host, ".prod.surfshark.com"), nil
|
||||
if net.ParseIP(host) != nil {
|
||||
return "", nil // ignore IP addresses
|
||||
}
|
||||
return strings.TrimSuffix(host, suffix), nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("could not find remote line")
|
||||
|
||||
Reference in New Issue
Block a user