-
Notifications
You must be signed in to change notification settings - Fork 41
/
NordVpnToWireguard.sh
executable file
·73 lines (63 loc) · 2.31 KB
/
NordVpnToWireguard.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
#!/bin/bash
VERSION="0.2.0"
ALLOPTIONS=$@
while [ "$1" != "" ];
do
case $1 in
-v | --version )
echo "Wireguard Config Files for NordVPN v$VERSION"
exit
;;
-h | --help )
echo "Usage: NordVpnToWireguard [command options] [<country>|<server>|<country_code>|<city>|<group>|<country> <city>]"
echo "Command Options includes:"
echo " <country> argument to create a Wireguard config for a specific country. For example: 'NordVpnToWireguard Australia'"
echo " <server> argument to create a Wireguard config for a specific server. For example: 'NordVpnToWireguard jp35'"
echo " <country_code> argument to create a Wireguard config for a specific country. For example: 'NordVpnToWireguard us'"
echo " <city> argument to create a Wireguard config for a specific city. For example: 'NordVpnToWireguard Hungary Budapest'"
echo " <group> argument to create a Wireguard config for a specific servers group. For example: 'NordVpnToWireguard connect Onion_Over_VPN'"
echo " -h | --help - displays this message."
exit
;;
esac
shift
done
# Connect to NordVPN
echo "Connect to NordVPN to gather connection parameters...."
nordvpn connect $ALLOPTIONS > /dev/null 2>&1 || {
echo "Unable to connect to NordVPN."
exit 1
}
# Use ip or ifconfig to get
if [ $(command -v ip &> /dev/null) ]; then
IP_ADDR_COMMAND="ip addr show"
else
IP_ADDR_COMMAND="ifconfig"
fi
# Preparing the I
# Gather all info
MYIP=$($IP_ADDR_COMMAND nordlynx | grep inet | awk '{print $2}')/32
PRIVATE=$(sudo wg show nordlynx private-key)
PUBKEY=$(sudo wg show nordlynx | grep peer | awk '{print $2}')
ENDPOINT=$(nordvpn status | grep 'Hostname' | awk '{print $2}')
OUTPUFILENAME="NordVPN-`echo $ENDPOINT | grep -o '^[^.]*'`.conf"
# Disconnect from NordVPN
nordvpn d > /dev/null 2>&1 || {
echo "Unable to disconnect from NordVPN."
exit 1
}
# Creating Wireguard Configuration file
cat <<EOF > $OUTPUFILENAME
[Interface]
Address = ${MYIP}
PrivateKey = ${PRIVATE}
ListenPort = 51820
DNS = 103.86.96.100, 103.86.99.100
[Peer]
PublicKey = ${PUBKEY}
AllowedIPs = 0.0.0.0/0, ::0/0
Endpoint = ${ENDPOINT}:51820
PersistentKeepalive = 25
EOF
echo "Wireguard configuration file $OUTPUFILENAME created successfully!"
exit 0