rauchg / wifi-password

Get the password of the wifi you're on (bash)
4.41k stars 237 forks source link

"wifi-password ERROR: Could not retrieve current SSID. Are you connected?" #34

Open BitGrub opened 3 months ago

BitGrub commented 3 months ago

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 commented 3 months ago

Same situation

BitGrub commented 3 months ago

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

haakonstorm commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

Any updates or ETA for a fix on this?

BitGrub commented 2 months ago

Any updates or ETA for a fix on this?

Nope

insasquatchcountry commented 3 weeks ago

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"