Skip to content

Instantly share code, notes, and snippets.

@loupzeur
Created September 14, 2021 20:01
Show Gist options
  • Save loupzeur/efc8fd21306a515db7bebaab4ce4677d to your computer and use it in GitHub Desktop.
Save loupzeur/efc8fd21306a515db7bebaab4ce4677d to your computer and use it in GitHub Desktop.
generate a wireguard configuration client with it's qrcode
#!/bin/bash
#this script generate a configuration for wg that is then send as a qrcode for android app
#require qrencode
if [ $# -lt 3 ];then
echo "require parameters
./script serverip:port client-net server-publickey
serverip:port 8.8.8.8:8989
client-net : 10.8.0.5/32
key : ...
"
exit
fi
SRV_IP=$1 #ip:port
CLT_NET=$2 #10.8.0.5/32
SRV_KEY=$3 #keys
PRKEY=`wg genkey`
PUKEY=`echo $PRKEY|wg pubkey`
echo -e "Private Key : $PRKEY\nPublic Key : $PUKEY"
conf="[Interface]
PrivateKey = $PRKEY
ListenPort = 1789
Address = $CLT_NET
DNS = 8.8.8.8
[Peer]
PublicKey = $SRV_KEY
AllowedIPs = 0.0.0.0/1, 128.0.0.0/1
Endpoint = $SRV_IP
"
echo "$conf"|qrencode -t ansiutf8
echo -e "Server will require : \nwg set wg0 peer $PUKEY allowed-ips $CLT_NET"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment