加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 按名称批量文件到网络上的MASS ping计算机组,检查回

发布时间:2020-12-13 23:42:09 所属栏目:Windows 来源:网络整理
导读:所以,我的 Windows Active Directory网络上有5000台计算机的列表,可能存在也可能不存在(我知道,不要问……我需要知道一个项目,当然,网络人员的帮助很少,他们给我的数据中有很多错误) 计算机名称属于SAT1至SAT5000. 但是,其中一些可能已升级到新操作系统并重
所以,我的 Windows Active Directory网络上有5000台计算机的列表,可能存在也可能不存在(我知道,不要问……我需要知道一个项目,当然,网络人员的帮助很少,他们给我的数据中有很多错误)

计算机名称属于SAT1至SAT5000.
但是,其中一些可能已升级到新操作系统并重命名.所以在这种情况下我想检测新名称.

我想知道是否有人可能有一个脚本,给定一个包含计算机名列表的文本文件,每个脚本:
1. ping计算机以检查是否存在(是的,它必须打开,我知道)
2.从第一次ping接收到ip后,执行ping -a获取主机名
3.将结果写入文本文件

(甚至更好……是否有可能以某种方式将初始文件拆分为多个文件,并生成多个批处理文件以同时运行,以降低同步ping 5000台机器的速度?)

更新

这篇文章似乎与我正在寻找的有些相关:
http://www.enterpriseitplanet.com/networking/features/article.php/1571771

更新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
这是一个批处理文件:
@echo off
rem Loop thru list of computer names 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.
ping -n 2 %1 >NUL 2>NUL
if errorlevel 1 goto down

rem Reverse-lookup machine name and report
for /f "usebackq tokens=2" %%d in (`ping -n 1 -a %1 ^| find "Pinging"`) do echo %1:Up:%%d
goto end

:down
rem Report machine down
echo %1:Down

:end

将一个包含计算机名称列表的文本文件传递给它,然后将它们PING它们(2次尝试 – 你可以通过增加第一个PING命令行中“-n”之后的数字来增加它),如果它得到了响应,执行名称的反向查找.它将结果返回为:

computer-name-1:Up:name-it-resolved-to
computer-name-2:Down
computer-name-3:Up:name-it-resolved-to
...

要并行运行多个,只需创建具有不同机器名列表的多个文本文件,并并行启动几个副本.

快速和肮脏节省了一天.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读