Compare commits

..

3 Commits

3 changed files with 18 additions and 1 deletions

View File

@ -9,6 +9,8 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2

13
README.md Normal file
View File

@ -0,0 +1,13 @@
# mullvad-best-server
Determines the mullvat.net server with the lowest latency.
## Installation
Download binary from releases for your platform and unpack.
## Usage
Execute `mullvad-best-server`. It outputs the code, e.g. `de05`. You can then connect to it with e.g. wireguard using the normal shell scripts.
## Background
The program uses `https://api.mullvad.net/www/relays/wireguard/` to get the current server list, pings the ones with the right country
and outputs the server with the lowest ping.

View File

@ -9,6 +9,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings"
"time" "time"
) )
@ -19,7 +20,8 @@ func main() {
servers := getServers() servers := getServers()
bestIndex := selectBestServerIndex(servers) bestIndex := selectBestServerIndex(servers)
log.Debug().Interface("server", servers[bestIndex]).Msg("Best latency server found.") log.Debug().Interface("server", servers[bestIndex]).Msg("Best latency server found.")
fmt.Println(servers[bestIndex].Hostname) hostname := strings.Split(servers[bestIndex].Hostname, "-")[0]
fmt.Println(hostname)
} }
func selectBestServerIndex(servers []server) int { func selectBestServerIndex(servers []server) int {