我正在处理一个应该对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
@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
答案 0 :(得分: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