wmic scan for windows然后执行其他命令?

时间:2015-12-16 13:17:00

标签: find wmic

    for /f "tokens=*" %%a in (ip.txt) do (
  set "_ready="
  for /F %%G in ('ping -4 -n 1 %%a^|find "TTL="') do set "_ready=%%G"
  if defined _ready (
      rem your `WMIC /FAILFAST:OFF /node:%%a …` 
         wmic /node:%%a /user: /password: computersystem get Name, domain, Manufacturer, Model, NumberofProcessors, PrimaryOwnerName,Username, Roles, totalphysicalmemory /format:list
         wmic /node:%%a /user: /password: cpu get Name, Caption, MaxClockSpeed, DeviceID, status /format:list
         wmic /node:%%a /user: /password: path Win32_VideoController get Name, status, DeviceID /format:list
         wmic /node:%%a /user: /password: os get Version, Caption, CountryCode, CSName, Description, InstallDate, SerialNumber, ServicePackMajorVersion, WindowsDirectory /format:list
         wmic /node:%%a /user: /password: csproduct get identifyingnumber /format:list

  )>"%%a.txt"
)
好的,所以我的脚本差不多完成了!我需要它来扫描Windows计算机,我不知道如何。

我可以使用wmic os get name并查找Windows吗?

wmic os get name | find "Windows" do ()一样不会工作但是......

这样的事情呢?

set "_ready="
for /F "tokens=9 delims=<=> " %%G in ('
    ping -4 -n 1 "%%~a" ^| find /I "TTL="') do (
  set "_ready=%%G"
)
set "oss=unknown"
if defined _ready (
  if !_ready! LEQ 64 (
      set "oss=*nix/HW"
  ) else ( 
    if !_ready! LEQ 128 (
      set "oss=Windows"
      rem your `WMIC` for /f "tokens=*" %%a in (ip.txt) do (
  set "_ready="
  for /F %%G in ('ping -4 -n 1 %%a^|find "TTL="') do set "_ready=%%G"
  if defined _ready (
      rem your `WMIC /FAILFAST:OFF /node:%%a …` 
         wmic /node:%%a /user: /password: computersystem get Name, domain, Manufacturer, Model, NumberofProcessors, PrimaryOwnerName,Username, Roles, totalphysicalmemory /format:list
         wmic /node:%%a /user: /password: cpu get Name, Caption, MaxClockSpeed, DeviceID, status /format:list
         wmic /node:%%a /user: /password: path Win32_VideoController get Name, status, DeviceID /format:list
         wmic /node:%%a /user: /password: os get Version, Caption, CountryCode, CSName, Description, InstallDate, SerialNumber, ServicePackMajorVersion, WindowsDirectory /format:list
         wmic /node:%%a /user: /password: csproduct get identifyingnumber /format:list

  )>"%%a.txt"
)

    ) else (
      set "oss=Solaris"
    )
  )
)

1 个答案:

答案 0 :(得分:1)

How to identify which OS is running at remote host?

  

您可以使用nmap。它不精确,但它可以给你一个线索。或者您   可以使用简单的“ping”并查找TTL

     
      
  • TTL=64 = * nix - 跳数,所以如果你得到61然后有3个跳和它的* nix设备。很可能是Linux。
  •   
  • TTL=128 = Windows - 如果TTL为127,则跳数为1且为Windows框。
  •   
  • TTL=254 = Solaris / AIX - 如果TTL为250,那么跳数是4,它是一个Solaris框。
  •   

获取变量TTL的{​​{1}}值:它是_ready成功TTL=行中的第9个标记:

ping

仅供参考,我的(较旧的)批处理脚本在路由到远程计算机时返回操作系统。为了您的目的,请注意set "_ready=" for /F "tokens=9 delims=<=> " %%G in (' ping -4 -n 1 "%%~a" ^| find /I "TTL="') do ( set "_ready=%%G" ) set "oss=unknown" if defined _ready ( if !_ready! LEQ 64 ( set "oss=*nix/HW" ) else ( if !_ready! LEQ 128 ( set "oss=Windows" rem your `WMIC` commands here ) else ( set "oss=Solaris" ) ) ) rem echo debug G: %%~G "%%~H" "%%~I"之间的代码段。请注意,它无法区分硬件(路由器)和echo(!no:~-3! !ip:~0,15! !tl:~-3! !oss! !hna! OS:

*nix

输出(为隐私而删除了“@ECHO OFF >NUL SETLOCAL EnableExtensions EnableDelayedExpansion set "cmnd=tracert -d -4" if "%~1"=="" ( set "target=%COMPUTERNAME%" ) else ( if "%~1"=="-1" ( set "target=d:\bat\files\tracertgol.txt" set "cmnd=type" ) else ( set "target=%~1" ) ) for %%a in ("%target%") do ( echo checking %%a for /F "tokens=1,2,8 delims= " %%G in (' %cmnd% "%%~a" ^| findstr /R /B "..[0-9].*[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*" ') do ( rem echo debug G: %%~G "%%~H" "%%~I" set "ttl=" set "hna=" for /F "tokens=1,2,9 delims=<=> " %%x in (' ping -a -4 -n 1 "%%~I" ^| findstr /I "Pinging TTL"') do ( rem echo debug x: %%~G %%~H "%%~I" %%x [%%y] %%z if /I "%%~x"=="Pinging" ( set "hna=%%~y" ) else ( set "ttl=%%z" ) ) set "oss=unknown" if defined ttl ( if !ttl! LEQ 64 ( set "oss=*nix/HW" ) else ( if !ttl! LEQ 128 ( set "oss=Windows" ) else ( set "oss=Solaris" ) ) ) rem call :display %%G %%I "!ttl!" "!oss!" "!hna!" set "no= %%~G" set "ip=%%~I " set "tl= !ttl!" echo(!no:~-3! !ip:~0,15! !tl:~-3! !oss! !hna! ) ) :endlocal ENDLOCAL goto :eof :display SETLOCAL set "no= %~1" set "ip=%~2 " set "tl= %~3" echo(%no:~-3% %ip:~0,15% %tl:~-3% %~4 %~5 ENDLOCAL goto :eof ”):

1..4