获取本机WLAN密码

前言

下载运行此BAT脚本,会在当前目录输出WiFi.txt文件。


方式一:PowerShell脚本

1
(netsh wlan show profiles) | Select-String "\:(.+)$" | %{$name=$_.Matches.Groups[1].Value.Trim(); $_} | %{(netsh wlan show profile name="$name" key=clear)}  | Select-String "(关键内容|Key Content)\W+\:(.+)$" | %{$pass=$_.Matches.Groups[2].Value.Trim(); $_} | %{ [pscustomobject]@{ '名称'=$name;'密码'=$pass }}
  1. 鼠标右键单击开始菜单按钮,打开PowerShell
  2. 将上述代码粘贴到终端
  3. 敲击回车键

方式二:CMD脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@echo off
color 2f
mode con: cols=40 lines=15
title WiFi密码查询
echo 正在查询结果
setlocal enabledelayedexpansion
for /f "tokens=2* delims=:" %%i in ('netsh wlan show profiles') do (
set str=%%i
for /f "tokens=3* delims= " %%d in ('netsh wlan show profiles key^=clear name^="!str:~1!"^| findstr "关键内容"') do (
echo "!str:~1!"密码为:【%%d
echo "!str:~1!"密码为:【%%d】>>WiFi.txt
)
)
echo 保存在脚本所在目录的WiFi.txt文件中
echo 任意键退出查询
pause>nul

将上述代码以ANSI编码方式保存到.txt文件,然后将文件后缀名改为.bat


后记

  • PowerShell脚本,感谢作者:kumamiko
  • CMD脚本,感谢作者