aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/contrib/examples/ncat-client-server/client-quick.sh
blob: 25ff6150ab16b5b36c6086faa6f132c4862cd65d (plain) (blame)
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
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.

set -e

echo "[!] Warning: This server is for testing purposes only. You may not use this server for abusive or illegal purposes."

echo "[+] Generating private key."
privatekey="$(wg genkey)"

echo "[+] Sending public key to server."
exec 7<>/dev/tcp/demo.wireguard.com/42912
wg pubkey <<<"$privatekey" >&7

echo "[+] Parsing server response."
IFS=: read -r status server_pubkey server_port internal_ip <&7
[[ $status == OK ]] || exit 1

echo "[+] Writing config file."
sudo sh -c 'umask 077; mkdir -p /etc/wireguard; cat > /etc/wireguard/demo.conf' <<_EOF
[Interface]
PrivateKey = $privatekey
Address = $internal_ip/24
DNS = 8.8.8.8, 8.8.4.4, 1.1.1.1, 1.0.0.1

[Peer]
PublicKey = $server_pubkey
Endpoint = demo.wireguard.com:$server_port
AllowedIPs = 0.0.0.0/0
_EOF

echo "[+] Success. Run \`wg-quick up demo\` to turn on the tunnel to the demo server and \`wg-quick down demo\` to turn it off."