所以,我的
Windows Active Directory网络上有5000台计算机的列表,可能存在也可能不存在(我知道,不要问……我需要知道一个项目,当然,网络人员的帮助很少,他们给我的数据中有很多错误)
计算机名称属于SAT1至SAT5000.
但是,其中一些可能已升级到新操作系统并重命名.所以在这种情况下我想检测新名称.
我想知道是否有人可能有一个脚本,给定一个包含计算机名列表的文本文件,每个脚本:
1. ping计算机以检查是否存在(是的,它必须打开,我知道)
2.从第一次ping接收到ip后,执行ping -a获取主机名
3.将结果写入文本文件
(甚至更好……是否有可能以某种方式将初始文件拆分为多个文件,并生成多个批处理文件以同时运行,以降低同步ping 5000台机器的速度?)
更新
更新2
这就是我最终的结果:
@echo off
rem del output.txt
rem Loop thru list of computer names in file specified on command-line
for /f %%i in (%1) do call :check_machine %%i
goto end
:check_machine
rem Check to see if machine is up.
echo %1
ping -n 2 %1 >NUL 2>NUL
if errorlevel 1 goto down
rem Reverse-lookup machine name and report
for /f "usebackq tokens=2,3" %%d in (`ping -n 1 -a %1 ^| find "Pinging "`) do echo %1, %%d,%%e >> output.txt
goto end
:down
rem Report machine down
echo %1 >> output.txt
:end
输出采用以下格式:
SAT10
SAT1209
SAT601, CGY2601.na.sat.com,[110.3.111.70]
SAT3592, CGY3592.na.sat.com,[110.0.237.45]
如果将计算机列表拆分为mutliple较小的文件,则可以异步ping,如下所示:
del output.txt
start MassPing.cmd Computers1.txt
start MassPing.cmd Computers2.txt
start MassPing.cmd Computers3.txt
start MassPing.cmd Computers4.txt
start MassPing.cmd Computers5.txt
start MassPing.cmd Computers6.txt