Skip to content

Instantly share code, notes, and snippets.

@msfjarvis
Created January 9, 2019 14:28
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save msfjarvis/77d6461211c35910a42f15898b3dad63 to your computer and use it in GitHub Desktop.
Collection of bash hackery to determine which Mullvad WireGuard server is the lowest latency from your location
  • Grab all your wireguard configs from Mullvad and dump them in a folder. For this test, this folder is ~/wireguard/.
  • Add the following function to generate a list of all servers you have configs for
lswg ()  { 
    ls ~/wireguard/ | cut -d '-' -f 2 | sed 's/\.conf//'
}
  • Ping each server 10 times to determine latency.
lswg | xargs -I {} ping -c 10 {}-wireguard.mullvad.net | tee mullvadwgstats
  • Programmatically determine the fastest servers with some epic bash-fu
grep transmitted mullvadwgstats | awk '{print $10}' | sed 's/ms//' | sort -n | head -n1 | xargs -I {} grep -C1 {} mullvadwgstats

The result from the last command will be something like this:

--- cz1-wireguard.mullvad.net ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9002ms
rtt min/avg/max/mdev = 167.181/186.360/272.822/32.254 ms
--
--- se4-wireguard.mullvad.net ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9002ms
rtt min/avg/max/mdev = 162.903/164.410/168.176/1.525 ms

Explanation of how this works

  • First we get a list of all available servers using the local copy of wireguard configs
  • Then we ping each server 10 times to establish a baseline for each. This output is also written to a file which will be used later.
  • grep for the transmitted word which lets us grab the stats line, use 'awk' to get the final ping time, remove the ms suffix, sort it, grab the first item, then use that to find the server name from the origianl stats file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment