问题描述
我正在创建这个批处理脚本来提取以前连接到我的设备的任何 Wi-Fi 的密码。这个脚本要求用户输入 SSID,然后提取密码使用 netsh wlan show profile=%Wi-Fi name% key=clear
,但在执行时,我多次遇到此错误:
' ' is not recognized as an internal or external command,operable program or batch file.
我尝试将变量 cmnd
替换为实际代码,即 netsh wlan....
语句中的 FOR \f
,但没有明显的输出可见。
对我做错了什么有什么建议吗?
我的代码:
@echo Welcome to this Password Extractor tool.
set /p WiFi_Name=Enter the SSID.
set cmnd=netsh wlan show profile name=%WiFi_Name% key=clear
for /f "tokens=1-2,17" %%i in ('%cmnd%') do ^
if "%%i %%j"=="Key Content" set PASS=%%k
echo%PASS%
Pause
Welcome to this Password Extractor tool.
C:\Program Files\PowerToys>set /p WiFi_Name=Enter the SSID.
Enter the SSID.Skti
C:\Program Files\PowerToys>set cmnd=netsh wlan show profile name=Skti key=clear
C:\Program Files\PowerToys>for /F "tokens=1-2,17" %i in ('netsh wlan show profile name Skti key clear') do
C:\Program Files\PowerToys>
' ' is not recognized as an internal or external command,operable program or batch file.
C:\Program Files\PowerToys>
' ' is not recognized as an internal or external command,operable program or batch file.
C:\Program Files\PowerToys>if "%i %j" == "Key Content" set PASS=%k
C:\Program Files\PowerToys>echo
ECHO is on.
解决方法
我建议你使用更强大的东西:
For /F "Tokens=3,*" %%G In ('%SystemRoot%\System32\netsh.exe WLAN Show Profiles Name^="%WiFi_Name%" Key^="Clear" 2^>NUL ^| %SystemRoot%\System32\findstr.exe /RC:"^ *Key Content *: *[^ ][^ ]*.*$"') Do Set "PASS=%%H"
...如果你想分割那条长线以提高可读性,那么:
For /F "Tokens=3,*" %%G In ('%SystemRoot%\System32\netsh.exe WLAN Show Profiles
Name^="%WiFi_Name%" Key^="Clear" 2^>NUL ^| %SystemRoot%\System32\findstr.exe
/RC:"^ *Key Content *: *[^ ][^ ]*.*$"') Do Set "PASS=%%H"
请注意,netsh.exe 输出是以配置的系统语言返回的,因此如果您打算分发它,请注意,任何密码都不会总是以英文区分大小写的字符串 {{ 1}}
,它可能会解决您的问题。
@ECHO OFF
echo Welcome to this Password Extractor tool.
set /p WiFi_Name=Enter the SSID:
netsh wlan show profile name=%WiFi_Name% key=clear>"%tmp%\wifi.log"
findstr /n "Key Content" "%tmp%\wifi.log">"%tmp%\wifi1.log"
del /q /f "%tmp%\wifi.log"
set /p pass=<%tmp%\wifi1.log
for /f "tokens=3 delims=:" %%a in ("%pass%") do (
SET PASS=%%a
)
SET PASS=%PASS%B
del /q /f "%tmp%\wifi1.log"
set PASS=%PASS:~1,-1%
ECHO PASSWORD: %PASS%
pause
它会在 TEMP 文件夹中创建一些必需的文件,并在操作完成后删除