我编写了一个批处理脚本,如下所示:
@echo off
setlocal enableextensions enabledelayedexpansion
set "outfile=wmic-full-output.txt"
for /L %%y in (73,1,79) do (
for /L %%z in (1,1,254) do (
echo ********************************************************* >> "!outfile!"
set "node=172.22.%%y.%%z"
echo !node! >> "!outfile!"
ping -n 1 -l 1 -w 1 !node! | find "Packets" >> "!outfile!"
if not errorlevel 1 (
nbtstat -A !node! >> !outfile!
nbtstat -A !node! | find /i "Host not found." >nul 2>&1 && ( echo Not a Windows Machine >> !outfile! ) || (
for /f "tokens=2-7 delims=," %%a in (
'wmic /node:"!node!" computersystem get domain^,manufacturer^,model^,name^,systemtype^,username^,wakeuptype /format:csv ^| find /i "!node!"'
) do (
set "_domain=%%a"
set "_manufacturer=%%b"
set "_model=%%c"
set "_name=%%d"
set "_systemType=%%e"
set "_userName=%%f"
for %%j in (!_username!) do (set "_username=%%j")
if "!_username!"=="6" (set "_username=Not Available")
)
for /f "tokens=2 delims=," %%a in (
'wmic /node:"!node!" bios get serialNumber^,version /format:csv ^| find /i "!node!"'
) do (
set "_serialNumber=%%a"
)
for /f "tokens=2-3 delims=," %%a in (
'wmic /node:"!node!" os get name^,totalvisiblememorysize^,version /format:csv ^| find /i "!node!"'
) do (
set "_osName=%%a"
for /f "tokens=1 delims=|" %%j in ("!_osName!") do (set "_osName=%%j")
set "_memory=%%b"
)
for /f "tokens=2 delims=," %%a in (
'wmic /node:"!node!" cpu get name^,version /format:csv ^| find /i "!node!"'
) do (
set "_cpu=%%a"
echo HostName= !_name! >> "!outfile!"
echo Domain= !_domain!>> "!outfile!"
echo UserName= !_userName! >> "!outfile!"
echo Manufacturer= !_manufacturer! >> "!outfile!"
echo Model= !_model! >> "!outfile!"
echo SystemType= !_systemType! >> "!outfile!"
echo SerialNumber= !_serialNumber! >> "!outfile!"
echo OperatingSystem= !_osName! >> "!outfile!"
echo RAM= !_memory! >> "!outfile!"
echo Processor= !_cpu! >> "!outfile!"
)
))
))
当在Windows服务器上执行上述脚本时,在成功执行最多172.22.73.12之后,它会永久暂停。当观察到outfile
内容时,记录的最新结果是nbtstat -A 172.22.73.13
的输出。
脚本有什么问题吗?
答案 0 :(得分:0)
测试一下:
@echo off
setlocal enableextensions enabledelayedexpansion
set "outfile=wmic-full-output.txt"
for /L %%y in (73,1,79) do (
for /L %%z in (1,1,254) do (
echo ********************************************************* >> "!outfile!"
set "node=172.22.%%y.%%z"
echo !node! >> "!outfile!"
ping -n 1 -l 1 -w 1 !node! | find /i "TTL=" >> "!outfile!"
if not errorlevel 1 (
nbtstat -A !node! >> !outfile!
nbtstat -A !node! | find /i "Host not found." >nul
if errorlevel 1 (
for /f "tokens=2-7 delims=," %%a in (
'wmic /node:"!node!" computersystem get domain^,manufacturer^,model^,name^,systemtype^,username^,wakeuptype /format:csv ^| find /i "!node!"'
) do (
set "_domain=%%a"
set "_manufacturer=%%b"
set "_model=%%c"
set "_name=%%d"
set "_systemType=%%e"
set "_userName=%%f"
for %%j in (!_username!) do (set "_username=%%j")
if "!_username!"=="6" (set "_username=Not Available")
)
for /f "tokens=2 delims=," %%a in (
'wmic /node:"!node!" bios get serialNumber^,version /format:csv ^| find /i "!node!"'
) do (
set "_serialNumber=%%a"
)
for /f "tokens=2-3 delims=," %%a in (
'wmic /node:"!node!" os get name^,totalvisiblememorysize^,version /format:csv ^| find /i "!node!"'
) do (
set "_osName=%%a"
for /f "tokens=1 delims=|" %%j in ("!_osName!") do (set "_osName=%%j")
set "_memory=%%b"
)
for /f "tokens=2 delims=," %%a in (
'wmic /node:"!node!" cpu get name^,version /format:csv ^| find /i "!node!"'
) do (
set "_cpu=%%a"
echo HostName= !_name! >> "!outfile!"
echo Domain= !_domain!>> "!outfile!"
echo UserName= !_userName! >> "!outfile!"
echo Manufacturer= !_manufacturer! >> "!outfile!"
echo Model= !_model! >> "!outfile!"
echo SystemType= !_systemType! >> "!outfile!"
echo SerialNumber= !_serialNumber! >> "!outfile!"
echo OperatingSystem= !_osName! >> "!outfile!"
echo RAM= !_memory! >> "!outfile!"
echo Processor= !_cpu! >> "!outfile!"
)
)
)
)
)
echo done
pause