0

我正在研究一个应该整理 ping 请求的脚本。

@ECHO OFF
FOR /L %%i IN (60,1,254) DO ping -n 1 10.100.121.%%i & IF %%i==Reply (
ECHO 10.100.121.%%i>>c:\Test\Online.txt
  ) ELSE (
ECHO 10.100.121.%%i>>c:\Test\Offline.txt
  )
pause

但它似乎没有按应有的方式工作。所有 IP 地址都会转到 offline.txt 文件,即使它们在线。

我做错了什么?

如果有人很友善,那么我想知道我是否可以使用“%online_ip%”变量为每个在线的ping请求运行此命令,而那些不在线的则发送到offline.txt

C:\Test\putty.exe "%online_ip%" -l "root" -pw "pw" -m C:\Test\Commands.txt

编辑:

foxidrive解决方案的“改进”版本!

@echo off
FOR /L %%i IN (60,1,254) DO (
   echo  Checking if host at 10.100.121.%%i is Online.
   ping -n 1 10.100.121.%%i >nul 
    if not errorlevel 1 (
      echo  Host is Online & echo  Starting SSH with Plink at 10.100.121.%%i & echo.
      echo y | plink.exe root@10.100.121.%%i -pw password -m c:\Test\Commands.txt
    ) else (
      echo  Host is Offline & echo.
      >>c:\Test\Offline.txt ECHO 10.100.121.%%i
   )
)
pause
4

1 回答 1

3

看看这对你有什么作用:

@echo off
FOR /L %%i IN (60,1,254) DO (
   echo pinging 10.100.121.%%i
   ping -n 1 10.100.121.%%i >nul 
    if not errorlevel 1 (
      echo running putty with 10.100.121.%%i
      C:\Test\putty.exe "%%i" -l "root" -pw "pw" -m C:\Test\Commands.txt
    ) else (
      echo 10.100.121.%%i offline
      >>c:\Test\Offline.txt ECHO 10.100.121.%%i
   )
)
pause
于 2013-08-16T15:02:27.020 回答