-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patham-i-mullvad.sh
executable file
·89 lines (68 loc) · 2.01 KB
/
am-i-mullvad.sh
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright (C) 2018 Daniel Gröber
not_on_mullvad() {
echo>&2
echo>&2
echo "!!! NOT ON MULLVAD !!!" >&2
echo "$1">&2
echo>&2
sleep 3
exit 123
}
warning() {
echo>&2
echo "$1">&2
}
echo -n 'Checking Mullvad...'>&2
# IP Leak check
mullvad_ip4="$( curl -4 -s --max-time 3 https://am.i.mullvad.net/json | jq -r '.mullvad_exit_ip' )"
mullvad_ip6="$( curl -6 -s --max-time 3 https://ipv6.am.i.mullvad.net/json | jq -r '.mullvad_exit_ip' )"
ip_check () {
local var msg
var="$1"; shift
msg="$1"; shift
local mullvad_ip
eval "mullvad_ip=\$$var"
if [ "$mullvad_ip" = 'false' ]; then
not_on_mullvad "- $msg Leaking"
exit 123 #not reached
elif [ "$mullvad_ip" = '' ]; then
warning "- $msg check errored"
return 1
fi
return 0
}
ip_check mullvad_ip4 "IPv4"; rv_ip4=$?
ip_check mullvad_ip6 "IPv6"; rv_ip6=$?
if [ $rv_ip4 -ne 0 ] && [ $rv_ip6 -ne 0 ]; then
not_on_mullvad "- All IP checks errored"
fi
dnsleak_domain=$(curl -s --max-time 3 https://am.i.mullvad.net/config | jq -r '.dns_leak_domain' )
# DNS Leak check
dnsids=
for i in $(seq 0 3); do
id=$(xxd -p -l16 < /dev/urandom)
dnsids="$dnsids $id"
(curl -s "https://$id.$dnsleak_domain/" > /dev/null 2>&1 || true)&
done
wait
for i in $dnsids; do
mullvad_dns="$(curl -s --max-time 10 https://am.i.mullvad.net/dnsleak/$id \
| jq '[ .[] | .mullvad_dns ] | all')"
if [ "$mullvad_dns" = '' ]; then
warning "- DNS check errored"
elif [ "$mullvad_dns" = 'false' ]; then
not_on_mullvad "- DNS Leaking"
fi
done
echo 'OK'>&2
if [ -r ~/.mullvad-expiry ]; then
expiry="$(cat ~/.mullvad-expiry)"
if which dateutils.ddiff > /dev/null 2>&1; then
dateutils.ddiff now "$expiry" -f 'Expires in %ddays %Hhours.' >&2
else
printf 'Expires on %s\n' "$(date -d "$expiry")" >&2
fi
fi