Created
March 31, 2018 08:00
-
-
Save elbosso/c01c3c271838e672461bea6841ba33be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Make sure only root can run our script | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" 1>&2 | |
exit 1 | |
fi | |
# Generate new wlan password and safe it. Don't use special chars to make it simpler | |
WLANPSK=$(pwgen -1Bv |tr '/' '$') | |
sed -ie "s/wpa_passphrase=.*/wpa_passphrase=${WLANPSK}/" /etc/hostapd.conf | |
service hostapd reload | |
ssid=$(grep "^ssid=" /etc/hostapd.conf|head -n 1|cut -d '=' -f 2) | |
ibs=$(grep "^ignore_broadcast_ssid=" /etc/hostapd.conf|head -n 1|cut -d '=' -f 2) | |
hidden="false" | |
if [ "${ibs}" == "0" ] | |
then | |
hidden="true" | |
fi | |
# Generate QR code pictures for Android and Windows | |
qrencode -t PNG -o /tmp/android.png -s 4 "WIFI:T:WPA;S:${ssid};P:${WLANPSK};H:${hidden};" | |
echo "WIFI:T:WPA;S:${ssid};P:${WLANPSK};H:${hidden};" | |
./terminalqr.py "WIFI:T:WPA;S:${ssid};P:${WLANPSK};H:${hidden};" >/tmp/android.txt | |
qrencode -t PNG -o /tmp/windows.png -s 4 "WIFI;T:WPA;S:${ssid};P:${WLANPSK};H:${hidden};" | |
./terminalqr.py "WIFI:T:WPA;S:${ssid};P:${WLANPSK};H:${hidden};" >/tmp/windows.txt | |
# IOS requires a hosted webpage which I do not want to host | |
# Use the copy to clipboard function for the password and manually connect instead. | |
qrencode -t PNG -o /tmp/ios.png -s 4 "${WLANPSK}" | |
./terminalqr.py "${WLANPSK}" >/tmp/ios.txt | |
echo "New WLAN password was generated and hostapd reloaded." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment