commit 1d21abc22d953ece1c2b4463e45a4a080eb34a62 Author: Atlaskor Date: Wed Aug 7 13:40:40 2024 -0600 Create IPDingv2.bat Reads a column of IP's, returns all that replied into successful.txt, all that did not reply go to error.txt. After they are created they are then also converted into CSV, and can be processed further. The primary use of this is to differentiate SNMP errors from equipment that is actually down. diff --git a/IPDingv2.bat b/IPDingv2.bat new file mode 100644 index 0000000..0c5a572 --- /dev/null +++ b/IPDingv2.bat @@ -0,0 +1,58 @@ +batch +Copy code +@echo off +setlocal enabledelayedexpansion + +REM Check if the file iplist.txt exists +if not exist iplist.txt ( + echo IP list file not found. + exit /b +) +REM Create an empty file named successful +echo. > successful.txt +echo. > error.txt +REM Read each line (IP address) from iplist.txt +for /f "tokens=*" %%A in (iplist.txt) do ( + set ip=%%A + echo Pinging !ip! + REM Run ping command and check if it was successful + ping !ip! -n 1 | find "TTL" > nul + if errorlevel 1 ( + echo !ip! did not reply + echo !ip! >> error.txt + ) else ( + echo !ip! replied + echo !ip! >> successful.txt + ) + echo. +) +echo Step 1 complete. +set "inputFile=successful.txt" +set "outputFile=processed.csv" +echo "Converting %inputFile% to %outputFile%..." + +( + echo Returned + for /f "usebackq tokens=*" %%A in ("%inputFile%") do ( + set "line=%%A" + REM Replace space with comma to convert to CSV + set "line=!line: =,!" + echo !line! + ) +) > "%outputFile%" +echo "Conversion completed. Output saved to %outputFile%." +echo Stage 2 complete. +set "inputFile=error.txt" +set "outputFile=processederror.csv" +echo "Converting %inputFile% to %outputFile%..." +( + echo Error + for /f "usebackq tokens=*" %%A in ("%inputFile%") do ( + set "line=%%A" + REM Replace space with comma to convert to CSV + set "line=!line: =,!" + echo !line! + ) +) > "%outputFile%" +echo "Conversion completed. Output saved to %outputFile%." +pause