|
本帖最后由 BEIKING 于 2023-9-18 19:52 编辑
- @echo off
- if /i "%UserName%" == "SYSTEM" (Goto GotAdmin) else (reg query "HKLM\SYSTEM\ControlSet001\Control\MiniNT" 1>nul 2>nul&&Goto GotAdmin)
- :BatchGotAdmin
- Set _Args=%*
- if `%1` neq `` Set "_Args=%_Args:"=""%"
- if exist %WinDir%\System32\fltMC.exe fltMC 1>nul 2>nul||mshta VBScript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c """"%~f0"" %_Args%""",,"runas",1)(Window.Close) 2>nul&&Exit /b
- :GotAdmin
- Pushd "%CD%"&cd /d "%~dp0"
- Title 获取目标系统 IP&Color 2f
- MODE 1>nul 2>nul&&MODE con: Cols=42 Lines=11
- :Start
- setlocal enabledelayedexpansion
- if `%1` neq `` Set Input=%1&Goto Input
- Set n=0&for %%i in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if exist "%%i:\Windows\System32\Config\SOFTWARE" if exist "%%i:\Windows\System32\Config\SYSTEM" Set /a n+=1&Set dsk!n!=%%i
- if !n! equ 1 Set Input=!dsk%n%!&MODE 1>nul 2>nul&&MODE con: Cols=42 Lines=7&Goto Input
- if !n! geq 2 Set /a l=7+!n!*2&MODE 1>nul 2>nul&&MODE con: Cols=42 Lines=!l!
- Call :EchoX "e0.:选择您要查询的目标系统↓"
- for /l %%i in (1,1,!n!) do echo.&Call :EchoX " " "9f::[%%i]" " " "xx.:!dsk%%i!:\Windows"
- echo.&Call :EchoX "70::输入序号[" "74::默认1" "70::]"&Set n=1&Set /p n=:
- Set Input=!dsk%n%!&if not defined Input Set Input=!n!
- :Input
- Set Input=%Input:~0,1%
- if /i "%Input%:" neq "%SystemDrive%" (
- for %%a in (SOFTWARE SYSTEM) do if not exist "%Input%:\Windows\System32\Config\%%a" Cls&Call :EchoX "cf.:找不到注册表文件!!"&echo "%Input%:\Windows\System32\Config\%%a"&Call :Delay 5 +&Exit
- reg load HKLM\IP_SOF %Input%:\Windows\System32\Config\SOFTWARE 1>nul 2>nul
- reg load HKLM\IP_SYS %Input%:\Windows\System32\Config\SYSTEM 1>nul 2>nul
- Call :GetIPInfo IP_SOF IP_SYS
- reg unload HKLM\IP_SOF 1>nul 2>nul
- reg unload HKLM\IP_SYS 1>nul 2>nul
- ) else Call :GetIPInfo SOFTWARE SYSTEM
- if exist "%TEMP%\IPInfo.txt" (msg 1>nul 2>nul&&msg * /time 3600<"%TEMP%\IPInfo.txt"||@start "" "%TEMP%\IPInfo.txt")
- Call :Delay 2 +
- endlocal
- Exit
- :GetIPInfo
- Call :EchoX "e0.:正在查询中,请稍候。。。"
- for /f "tokens=1,2*" %%a in ('reg query "HKLM\%2\select" 2^>nul') do if /i "%%a" == "Default" Set /a x=%%c
- Set "v1=Microsoft\Windows NT\CurrentVersion\NetworkCards"
- Set "v2=ControlSet00%x%\Control\Network"
- Set "v3=ControlSet00%x%\services\Tcpip\Parameters"
- Set "s=EnableDHCP NameServer IPAddress SubnetMask DefaultGateway"
- Set "s=%s% DHCPNameServer DHCPIPAddress DHCPSubnetMask DHCPDefaultGateway"
- Set n=&for /f "delims=" %%a in ('reg query "HKLM\%1\%v1%" 2^>nul') do (
- Set "v=%%a"
- if "!v:%v1%\=!" neq "!v!" (
- Set /a n+=1
- for /f "tokens=1,2*" %%b in ('reg query "%%a" 2^>nul') do if /i "%%b" == "ServiceName" (Set "Guid!n!=%%d") else if /i "%%b" == "Description" Set "NetCard!n!=%%d"
- )
- )
- if not defined n Call :EchoX "cf.:找不到网卡!!"&Call :Delay 5 +&Exit
- (for /f "tokens=1,2*" %%a in ('reg query "HKLM\%2\%v3%" 2^>nul') do (
- if /i "%%a" == "Domain" (
- if "%%c" neq "" (echo 域名名称:%%c) else echo 域名名称:
- ) else if /i "%%a" == "HostName" echo 主机名称:%%c
- )) >"%TEMP%\IPInfo.txt"
- for %%a in (%s%) do Set "_%%a=1"
- (for /l %%a in (1 1 %n%) do (
- echo.&echo 网卡名称:!NetCard%%a!
- for %%b in (%s%) do Set "%%b="
- Set flag=&for /f "delims=" %%b in ('reg query "HKLM\%2\%v2%" /s 2^>nul') do (
- if defined flag (
- for /f "tokens=1,2*" %%c in ("%%b") do if /i "%%c" == "Name" echo 连接名称:%%e& Set "flag="
- ) else (
- Set "v=%%b"
- for %%c in ("\!Guid%%a!") do if "!v:%%~c=!" neq "!v!" Set flag=1
- )
- )
- for /f "tokens=1,2*" %%b in ('reg query "HKLM\%2\%v3%\Interfaces\!Guid%%a!" 2^>nul') do if defined _%%b if "%%d" neq "" Set "v=%%d"&Set "%%b=!v:\0= !"
- if defined IPAddress (echo IP地址:!IPAddress!) else echo IP地址:!DHCPIPAddress! [自动获取]
- if defined SubnetMask (echo 子网掩码:!SubnetMask!) else echo 子网掩码:!DHCPSubnetMask!
- if defined DefaultGateway (echo 默认网关:!DefaultGateway!) else echo 默认网关:!DHCPDefaultGateway!
- if defined NameServer (Set DNS=!NameServer: =,!&Set dhcp=) else (Set DNS=!DHCPNameServer: =,!&Set dhcp= [自动获取])
- Set d=DNS 地址:&for %%i in (!DNS!) do if not defined "n%%a_%%i" echo !d!%%i!dhcp!&Set ""n%%a_%%i"=%%a"&Set dhcp=&Set d=
- )) >>"%TEMP%\IPInfo.txt"
- Goto :eof
- :Delay :: 延迟操作 <%1=Sec|延迟秒数> [%2=+|显示倒计时]。
- if `%2` == `+` (Set n=2) else Set n=1
- if exist %WinDir%\System32\timeout.exe (timeout /t %1 %n%>nul) else if exist %WinDir%\System32\choice.exe (choice /t %1 /d y /n >nul) else ping 127.1 -n %1 >nul
- Goto :eof
- :EchoX :: 显示彩色文字 (不支持半角字符 \ / : * ? " < >|. % ! ~)。
- setlocal enabledelayedexpansion
- Set echox=EchoX.exe&&!echox! 1>nul 2>nul||(Set echox=&mkdir "%TEMP%\EchoX" 2>nul)
- for %%a in (%*) do (
- Set "param=%%a"&Set "param=!param:"=!"
- Set "color=!param:~0,2!"&(if not exist %WinDir%\System32\findstr.exe if not defined echox Set "color=xx")
- Set n=0&(if "!param:~2,2!" == "::" Set n=1)&(if "!param:~2,2!" == ".:" Set n=2)
- if !n! gtr 0 (
- if /i "!color!" == "xx" (Set /p="_!param:~4!"<nul) else (Set param=%%~nxa&if defined echox (!echox! -c !color! -n "!param:~4!") else (Pushd "%TEMP%\EchoX" 2>nul&>"!param:~4!",Set /p= <nul&findstr /a:!color! .* "!param:~4!*"&del "!param:~4!"&Popd))
- if !n! == 2 echo.
- ) else if defined param Set /p="_!param!"<nul
- )
- endlocal
- Goto :eof
复制代码
批处理脚本用途:
获取(离线和在线)Win系统主机:域名名称、主机名称、网卡信息(连接名称、IP地址、子网掩码、默认网关、DNS地址)
读取离线注册表IP信息方法非原创,借鉴的是无忧某位坛友分享的。
允许传参调用:
获取目标系统IP.bat C
获取目标系统IP.bat D
【20230916】
1)释放临时文件到%TEMP%目录,避免因当前目录无写权限而报错。
2)格式化DNS地址输出并去重。
【20230918】
1)优化多系统选择体验,单一系统自动打开查询,多系统提供列表选择
2)支持网卡多IP设置查询
链接: https://pan.baidu.com/s/1tVJv4NWAY9bkzIy6VSHX_w 提取码: sad4
|
评分
-
查看全部评分
|