Reputation: 2593
Working on makeing a troubleshooting guide automatic , so i as a tech can just press..start.. This is one of the steps I am stuck at, Any help on how i can make a batch file do this?
Check procedure:
1. Ping 10.70.222.62 -t
Look for any dropped packets. > or = 1%, send at least 100 pings.
2.Check the subnet mask
3.Check the default gateway
4.Check NIC configuration. If more than 1 NIC is installed then only one should have the gateway set.
If all OK, then network is OK.
I am not much of a network guy , so when it says something like check the subnet mask, i am not sure what is ment by that or what i am checking it for. Also the NIC configuration may be hard to check with a batch file? thanks.
found some more info that may help..
Subnet Mask 255.255.254.0
Default Gateway 10.72.170.1
I did change a few numbers but i can change them back in the code once needed.
Step 1 so far..
ping -n 100 x.x.x.x | find "TTL"
if not errorlevel 1 set error=FAILED
if errorlevel 1 set error=PASSED
echo Result: %error%
only problem is it shows all the pings, anyway to have it not show the pings?
step 2 i figure you have to do a ipconfig and find the results? but not sure how.. same for step 3
Step 4 i have no idea what its even talking about...
Upvotes: 0
Views: 274
Reputation: 68
The for command will help you hide the pings. Following Stephen's answer, here's what you want:
Step 1,2,3 :-
@echo off
echo Checking ping...
set state=FAILED
for /f "tokens=5,7" %%a in ('ping x.x.x.x -n 100') do (
if "%%a"=="Received" if "%%b"=="100," set state=PASSED
)
echo Getting IP configuration...
ipconfig > stats.txt
find "Subnet Mask" stats.txt
find "Gateway" stats.txt
del stats.txt
pause
Step 4 :- I really don't know how to do that in batch...try using third party software.
Upvotes: 1
Reputation: 56180
Step 1: it would be easier to look for "(0% loss)" instead of "TTL", because finding TTL may mean, you tried 100 times and only one or two responses would repturn PASSED. (don't search for "0%", because that would find also 10% 20%...)
ping -n 100 x.x.x.x >nul |find "(0%"
Step 2,3:
Get the configuration to a file with ipconfig >stats.txt
get desired values with find "Subnet Mask" stats.txt
and find "Gateway" stats.txt
Step 4 is not trivial, I would like to leave that to someone else
Upvotes: 0