Skip to content
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

Open
BitGrub opened this issue Mar 16, 2024 · 7 comments

Comments

@BitGrub
Copy link

BitGrub commented Mar 16, 2024

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

@DmytroLitvinov
Copy link

Same situation

@BitGrub
Copy link
Author

BitGrub commented Mar 23, 2024

The app doesn't work since Ventura, I think? Something to do with root privileges

@haakonstorm
Copy link

This script relies on the airport cli utility, which is deprecated by Apple now.
("/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport")

Here is a modified bare bones script that gets the current SSID's password via networksetup instead:

#!/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"

@luckman212
Copy link

That's a good start @haakonstorm, but the WiFi interface won't always be en0. Also, using AWK to split on : could fail if the SSID itself contains colons.

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"

@pablofullana
Copy link

Any updates or ETA for a fix on this?

@BitGrub
Copy link
Author

BitGrub commented Apr 25, 2024

Any updates or ETA for a fix on this?

Nope

@insasquatchcountry
Copy link

Any updates or ETA for a fix on this?

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants