Skip to content

Commit d2aec1a

Browse files
committed
Merge branch 'mr5-python3' of https://github.com/munkireport/wifi into mr5-python3
2 parents df29f09 + 0a6912f commit d2aec1a

File tree

1 file changed

+35
-23
lines changed

1 file changed

+35
-23
lines changed

scripts/wifi

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -222,33 +222,45 @@ def get_wifi_ssid():
222222
except Exception:
223223
return False
224224

225+
# For macOS 15.7 and macOS 26 (Darwin 25+ / 26+)
225226
else:
226-
# Fallback method for macOS 15.7 and 26+
227-
plist = FoundationPlist.readPlist("/Library/Preferences/com.apple.wifi.known-networks.plist")
227+
# ✅ September 2025 fix (snelson.us)
228+
# Use ipconfig getsummary to retrieve SSID safely (works when wdutil redacts)
229+
try:
230+
subprocess.run(['/usr/sbin/ipconfig', 'setverbose', '1'], check=False)
228231

229-
ssid = ""
230-
date = ""
232+
cmd = """/usr/sbin/ipconfig getsummary en0 | awk -F ' SSID : ' '/ SSID : / {print $2}'"""
233+
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
234+
(output, _) = proc.communicate()
235+
ssid = output.decode("utf-8", errors="ignore").strip()
231236

232-
for wifi in plist:
233-
234-
# Check that we have the SSID in the preference file and it contains a BSSList entry
235-
if "BSSList" in plist[wifi]:
236-
# Process each BSS entry
237-
for bss in plist[wifi]['BSSList']:
238-
if 'BSSID' in bss and date == "":
239-
# If first check, save the date if exists and ssid
240-
ssid = wifi.replace('wifi.network.ssid.', "")
241-
if 'LastAssociatedAt' in bss:
242-
date = bss['LastAssociatedAt']
243-
elif 'BSSID' in bss and 'LastAssociatedAt' in bss and bss['LastAssociatedAt'] > date:
244-
# Compare other bssid entries to make sure none of them are newer
245-
ssid = wifi.replace('wifi.network.ssid.', "")
246-
date = bss['LastAssociatedAt']
237+
subprocess.run(['/usr/sbin/ipconfig', 'setverbose', '0'], check=False)
247238

248-
if ssid != "":
249-
return ssid
250-
else:
251-
return False
239+
if ssid:
240+
return ssid
241+
else:
242+
return False
243+
244+
except Exception:
245+
# Fallback: use known-networks plist as a last resort
246+
try:
247+
plist = FoundationPlist.readPlist("/Library/Preferences/com.apple.wifi.known-networks.plist")
248+
ssid = ""
249+
date = ""
250+
251+
for wifi in plist:
252+
if "BSSList" in plist[wifi]:
253+
for bss in plist[wifi]['BSSList']:
254+
if 'BSSID' in bss and date == "":
255+
ssid = wifi.replace('wifi.network.ssid.', "")
256+
if 'LastAssociatedAt' in bss:
257+
date = bss['LastAssociatedAt']
258+
elif 'BSSID' in bss and 'LastAssociatedAt' in bss and bss['LastAssociatedAt'] > date:
259+
ssid = wifi.replace('wifi.network.ssid.', "")
260+
date = bss['LastAssociatedAt']
261+
return ssid if ssid else False
262+
except Exception:
263+
return False
252264

253265
def get_wifi_bssid(ssid):
254266

0 commit comments

Comments
 (0)