I am in need of help doing a FOR /F Do loop in a CMD Batch script.
I am trying to write a batch script that will ping all IP addresses in a host file except for an IP address that starts with 127 and skip all commented lines in the hostfile or that start with a #.
my current code will ping the first word/string in every uncommented line, so I am halfway there. However I can't figure out how to compare the first 4 characters in the word/sting to 127. and have it skip it if starts with those characters.
Here is my working code. Any help will be appreciated.
I am trying to write a batch script that will ping all IP addresses in a host file except for an IP address that starts with 127 and skip all commented lines in the hostfile or that start with a #.
my current code will ping the first word/string in every uncommented line, so I am halfway there. However I can't figure out how to compare the first 4 characters in the word/sting to 127. and have it skip it if starts with those characters.
Here is my working code. Any help will be appreciated.
Code:
@ECHO off
setlocal EnableExtensions EnableDelayedExpansion
DEL C:\temp\Pings.txt
ECHO. > C:\temp\Pings.txt
For /F "eol=# tokens=1" %%A in (c:\temp\TESThost) do ECHO PING -a "%%A" && ECHO. >> C:\temp\Pings.txt && ECHO. >> C:\temp\Pings.txt && ECHO PING -a "%%A" >> C:\temp\Pings.txt && PING -a "%%A" >> C:\temp\Pings.txt && ECHO ---------------------------------------------------------------- >> C:\temp\Pings.txt
My Computer
At a glance
Windows 7 Ultimate x64
- OS
- Windows 7 Ultimate x64