-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"wifi-password ERROR: Could not retrieve current SSID. Are you connected?" #34
Comments
Same situation |
The app doesn't work since Ventura, I think? Something to do with root privileges |
This script relies on the Here is a modified bare bones script that gets the current SSID's password via #!/usr/bin/env zsh
# Original script by rauchg/wifi-password.
# Ventura/Sonoma deprecated the macos "airport CLI".
# Patched by haakonstorm to use networksetup instead
echo Enter admin pwd when prompted by macos dialog.
ssid=`networksetup -getairportnetwork en0 | awk -F": " '{print $2}'`
echo SSID: "$ssid"
pwd="`security find-generic-password -ga \"$ssid\" 2>&1 >/dev/null`"
pwd=$(echo "$pwd" | sed -e "s/^.*\"\(.*\)\".*$/\1/")
echo password:
echo "\033[96m$pwd\033[39m" |
That's a good start @haakonstorm, but the WiFi interface won't always be Here's a different approach that I've been using: #!/usr/bin/env bash
if [[ -n $1 ]]; then
SSID=$1
else
WIFI_IF=$(scutil <<< "list" | grep -m1 'AirPort' | awk -F/ '{print $(NF-1)}')
SSID=$(networksetup -getairportnetwork "${WIFI_IF}" | sed -En 's/Current Wi-Fi Network: (.*)$/\1/p')
[[ -n $SSID ]] || { echo 1>&2 "error retrieving current SSID. are you connected?"; exit 1; }
fi
echo -e "\033[90m … getting password for \"${SSID}\". \033[39m"
echo -e "\033[90m … keychain prompt incoming. \033[39m"
SECOUT=$(security find-generic-password -ga "${SSID}" 2>&1 >/dev/null)
(( $? == 128 )) && { echo "user cancelled"; exit 0; }
PASS=$(sed -En 's/^password: "(.*)"$/\1/p' <<<"$SECOUT")
[[ -n $PASS ]] || { echo 1>&2 "password for \"${SSID}\" not found in Keychain"; exit 1; }
echo -e "\033[96m ✓ ${PASS} \033[39m" |
Any updates or ETA for a fix on this? |
Nope |
I just took the script above and put where I keep my executable scripts and gave it permission to run. I could tell you how to do all that, but its best that you learn for yourself :) I named mine "wifi" |
I tweaked @luckman212's script a small bit so I don't always have to supply the SSID of the WiFi connection I'm currently on to get it to display the password. Bear in mind that this doesn't account for cases where your WiFi interface is NOT
#!/usr/bin/env bash
if [[ -n $1 ]]; then
SSID=$1
else
# WIFI_IF=$(iscutil <<< "list" | grep -m1 'AirPort' | awk -F/ '{print $(NF-1)}')
SSID=$(ipconfig getsummary en0 | awk -F ' SSID : ' '/ SSID : / {print $2}')
[[ -n $SSID ]] || { echo 1>&2 "error retrieving current SSID. are you connected?"; exit 1; }
fi
echo -e "\033[90m … getting password for \"${SSID}\". \033[39m"
echo -e "\033[90m … keychain prompt incoming. \033[39m"
SECOUT=$(security find-generic-password -ga "${SSID}" 2>&1 >/dev/null)
(( $? == 128 )) && { echo "user cancelled"; exit 0; }
PASS=$(sed -En 's/^password: "(.*)"$/\1/p' <<<"$SECOUT")
[[ -n $PASS ]] || { echo 1>&2 "password for \"${SSID}\" not found in Keychain"; exit 1; }
echo -e "\033[96m ✓ ${PASS} \033[39m" |
This worked for me on macOS 15.2 👍 |
Okay
…On Fri, 17 Jan 2025, 6:36 pm insasquatchcountry, ***@***.***> wrote:
I tweaked @luckman212 <https://github.com/luckman212>'s script a small
bit so I don't always have to supply the SSID of the WiFi connection I'm
currently on to get it to display the password.
Bear in mind that this doesn't account for cases where your WiFi interface
is NOT en0
$WIFI_IF was returing ap1 for me, which meant $SSID was choking, hence
this change.
This worked for me on macOS 15.2 👍
—
Reply to this email directly, view it on GitHub
<#34 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AT72UO77ZKE3GUJ66X2EMMD2LEPPJAVCNFSM6AAAAABVME2TW6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKOJYGYZDMNRRGU>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
If you want a generic method to detect the WiFi interface, that doesn't hardcode _get_wifi_ifname() {
scutil <<< list | awk -F/ '/Setup:.*AirPort$/ {print $(NF-1)}'
}
export -f _get_wifi_ifname
_get_wifi_ssid() {
local IFNAME
IFNAME=$(_get_wifi_ifname)
[[ -n $IFNAME ]] || return 1
ipconfig getsummary "$IFNAME" |
sed -En 's/^[[:space:]]*SSID : (.*)$/\1/p'
}
export -f _get_wifi_ssid |
@luckman212 thanks for sharing these. Unfortunately, When I run this: WIFI_IF=$(scutil <<< list | awk '/AirPort$/') I get the following output, which explains why I was getting
Are you aware of a surefire way to pick up the currently active interface? I'm happy to leave things as they are with Thanks loads. |
Try this one, it may work for you: _get_wifi_ifname() {
scutil <<< list | awk -F/ '/en[0-9]+\/AirPort$/ {print $(NF-1);exit}'
}
export -f _get_wifi_ifname |
Thanks loads @luckman212 , that worked. |
Getting the error message "ERROR: Could not retrieve current SSID. Are you connected?" if I try to use wifi-password
Manually specifying the SSID works, it just can't detect my current Wifi connection. Help?
I'm on MacOS Sonoma 14.4, M1 macbook pro
The text was updated successfully, but these errors were encountered: