Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm trying to create a batch file to ping a given IP address then, if this fails I want it to try pinging the same address but with .1 at the end of the ip instead. I can't work out how to set the variable to filter out the first three parts of the ip address to make xxx.xxx.xxx.1.
EXAMPLE: the batch file asks for an IP address, you enter 123.123.123.123. it tries to ping this address and, if this fails, it tries to ping 123.123.123.1.
I'd like the output of each ping recorded in a text file too (or the clipboard if possible).Here's what I have so far:
@echo off
SET /P GIVENIP=Enter IP Address:
ping %GIVENIP% | findstr /I "Reply from" > nul 2>&1
if errorlevel 1 (
echo.%GIVENIP% - No response to ping.
pause
REM Try to ping .1 IP address here
)
else (
echo.%GIVEN% - Ping success!
)

To parse and modify your IP address insert the following statement (that fits ONE line) that replaces the last token with 1
For /F "tokens=1-3 delims=." %%A in ("%GIVENIP%")Do Set GIVENIP=%%A.%%B.%%C.1

![]() |
sed ascii characters
|
mystery char in redirecte...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |