获取当前网络已连接的WIFI密码-来自utools插件

const cp = require('child_process')
let wifiPass
if (utools.isWindows()) {
  let stdoutBuffer = cp.execFileSync('netsh', ['wlan', 'show', 'interface'])
  let stdoutText = new TextDecoder('gbk').decode(stdoutBuffer)
  let ret = /^\s*SSID\s*: (.+)\s*$/gm.exec(stdoutText)
  if (!ret) throw new Error('未找到网络已连接的 WiFi 名称')
  const args = ['wlan', 'show', 'profile', `name=${ret[1]}`, 'key=clear']
  stdoutBuffer = cp.execFileSync('netsh', args)
  stdoutText = new TextDecoder('gbk').decode(stdoutBuffer)
  ret = /^\s*(?:Key Content|关键内容)\s*: (.+)\s*$/gm.exec(stdoutText)
  if (!ret) throw new Error('未能获取 WiFi 密码')
  wifiPass = ret[1]
} else if (utools.isMacOS()) {
  let stdoutText = cp.execFileSync('/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport', ['-I']).toString()
	if (stdoutText.includes('AirPort: Off')) throw new Error('WiFi 已关闭')
	let ret = /^\s*SSID: (.+)\s*$/gm.exec(stdoutText)
  if (!ret) throw new Error('未找到网络已连接的 WiFi 名称')
	const args = ['find-generic-password', '-D', 'AirPort network password', '-wa', ret[1]]
  wifiPass = cp.execFileSync('security', args).toString().trim()
}
utools.copyText(wifiPass)
print('WiFi 密码已复制')
return 'WiFi 密码:' + wifiPass

 

版权声明:
作者:k, k
链接:http://kuyour.top/index.php/2023/09/28/%e8%8e%b7%e5%8f%96%e5%bd%93%e5%89%8d%e7%bd%91%e7%bb%9c%e5%b7%b2%e8%bf%9e%e6%8e%a5%e7%9a%84wifi%e5%af%86%e7%a0%81-%e6%9d%a5%e8%87%aautools%e6%8f%92%e4%bb%b6/
来源:KuKey
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
海报
获取当前网络已连接的WIFI密码-来自utools插件
const cp = require('child_process') let wifiPass if (utools.isWindows()) { let stdoutBuffer = cp.execFileSync('netsh', ['wlan', 'show', 'interf……
<<上一篇
下一篇>>