- Copy the contents of the code block below.
- Paste it into a file
- Save it as
generate-wifi-config.sh
- Execute:
chmod +x ./generate-wifi-config.sh
to make it executable.
Note: Upon execution, your operating system is going to ask for your machine password. It does this because the script obtains your Wi-Fi password that is stored in the macOS Keychain.
#!/usr/bin/env bash
__getSSID(){
/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk '/[[:space:]]+SSID/{print $2}'
}
__getAuthType(){
my_auth_type="$(/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk '/link auth/{print $3}')"
case $my_auth_type in
WEP*|wep*)
echo "WEP"
;;
WPA*|wpa*)
echo "WPA"
;;
WPA2-EAP)
echo "WPA2-EAP"
;;
esac
}
__getWiFiPass(){
mySSID="$1"
security find-generic-password -a "${mySSID}" -w
}
main(){
ssid="$(__getSSID)"
auth_type="$(__getAuthType)"
wifi_password="$(__getWiFiPass "${ssid}")"
echo "WIFI:T:${auth_type};S:${ssid};P:${wifi_password};;"
}
main
In order to create the qrcode, we need to install qrencode
. The following step assume you have homebrew installed, if you do not, please install it.
brew install qrencode
Once you've installed qrencode
, execute:
qrencode -o join-wifi-qrcode.png < <(./generate-wifi-card.sh)
Now grab your phone, unjoin your network, open join-wifi-qrcode.png
and test your qr code!
Cheers!