batch-file - 当我对网络名称使用通配符时,网络的关键内容丢失

标签 batch-file networking passwords

我对 Windows NT 批处理脚本非常缺乏经验,并试图编写一个脚本来显示我保存的所有网络的密码。

程序在我使用确切的网络名称时有效,但在名称中使用通配符时无效。

例如,这会显示 Network1 的信息,包括密码:

@echo off
netsh wlan show profile name=Network1 key=clear
@pause

这会显示我保存的所有网络信息,除了它们的密码:

@echo off
netsh wlan show profile name=* key=clear
@pause

最佳答案

这是一个完整的例子 Wifi Passwords Recovery.bat

应该以管理员身份运行以显示 wifi key !

@echo off & setlocal enabledelayedexpansion
Set "Copyright=by Hackoo 2017"
Title  %~n0 %Copyright%
Mode con cols=75 lines=8
cls & color 0A & echo.
    echo             ***********************************************
    echo                 %~n0 %Copyright%
    echo             ***********************************************
    echo(
if _%1_==_Main_  goto :Main
Set Count=0
Set L=0
:getadmin
    echo               %~nx0 : self elevating
    set vbs=%temp%\getadmin.vbs
(
    echo Set UAC = CreateObject^("Shell.Application"^)
    echo UAC.ShellExecute "%~s0", "Main %~sdp0 %*", "", "runas", 1
)> "%vbs%"
    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
goto :eof
::*************************************************************************************
:Main
Call :init
Call :CountLines
Set "PasswordLog=%~dp0Wifi_Passwords_on_%ComputerName%.txt"
%Mod%
    echo(
    echo             ***********************************************
    echo                 %~n0 %Copyright%
    echo             ***********************************************
    echo(
Call :Color 0E "                 [N][SSID] ================ Password" 1
echo(
(
    echo             ***********************************************
    echo                 %~n0 %Copyright%
    echo             ***********************************************
    echo(
    echo                  [N][SSID] ==============^> "Password"
    echo(

)>"%PasswordLog%"
for /f "skip=2 delims=: tokens=2" %%a in ('netsh wlan show profiles') do (
    if not "%%a"=="" (
        set "ssid=%%a"
        set "ssid=!ssid:~1!"
        call :Getpassword "!ssid!"
    )
)
echo(
echo Done
If exist "%PasswordLog%" start "" "%PasswordLog%"
pause>nul
exit
::*************************************************************************************
:Getpassword
set "name=%1"
set "name=!name:"=!"
Set "passwd="
for /f "delims=: tokens=2" %%a in ('netsh wlan show profiles %1 key^=clear ^|find /I "Cont"') do (
    set "passwd=%%a"
    Set /a Count+=1
)

If defined passwd (
    set passwd=!passwd:~1!
    echo                  [!Count!][!name!] ====^> "!passwd!"
    echo                  [!Count!][!name!] ====^> "!passwd!" >> "%PasswordLog%"
) else (
    Set /a Count+=1
call :color 0C "                 [!Count!][!name!] The Password is empty" 1
    echo                  [!Count!][!name!] The Password is empty >> "%PasswordLog%"
)
exit /b
::*************************************************************************************
:init
prompt $g
for /F "delims=." %%a in ('"prompt $H. & for %%b in (1) do rem"') do set "BS=%%a"
exit /b
::*************************************************************************************
:color
set nL=%3
if not defined nL echo requires third argument & pause > nul & goto :eof
if %3 == 0 (
    <nul set /p ".=%bs%">%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
) else if %3 == 1 (
    echo %bs%>%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
)
exit /b
::*************************************************************************************
:CountLines
for /f "skip=2 delims=: tokens=2" %%a in ('netsh wlan show profiles') do (
    if not "%%a"=="" (
        set /a L+=1
    )
)
set /a L=!L! + 10
Set Mod=Mode con cols=75 Lines=!L!
exit /b
::*************************************************************************************

输出结果是这样的: enter image description here

关于batch-file - 当我对网络名称使用通配符时,网络的关键内容丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49196145/

相关文章:

windows - 如何在批处理文件中更改为当前用户的目录

batch-file - 我需要帮助,当用户输入非法字符时如何停止关闭此批处理文件

algorithm - 哪个集群节点应该处于事件状态?

android - Android中的密码提示字体

batch-file - 批处理内调用批处理?

batch-file - 打开带有给定字符串的 URL |在每次 URL 运行时从字符串中去除一个字符

c - 如何向内核发送数据包?

testing - TinyOS 和 Contiki 中的 6loWPAN 堆栈兼容吗?

hash - 我可以在摘要式身份验证中使用已 MD5 编码的密码吗

android - 恢复我的 keystore 的密码