![]() |
Batch file to ping network
Hi Guys,
I need some help writing a batch file to test network connectivity for various locations. Basically we are transitioning to from an existing network provider to a new network provider. What I would like the script to do Ping a list of IP address and then output the results into a simple text file of each IP Address. The text file ideally should just display something along the lines of ping www.google.com Successful or ping www.google.com Unsuccessful This is what I have so far but it is a bit broken. Code:
@echo offThanks! |
I don't know much about programming, but what about an "Else" statement?
This guy knows more: Batch files branching |
haha we are on the same boat, I'm clueless when it comes to programming.
I'll give it a go =) |
|
Thats a good idea however could we make the text file name indicate if it was successful or not or is that the complicated bit?
Also on another note would it be easier to do this in vb script? |
No, batch files are extremely easy.
A "If" requires three extra steps. Code is not how much you can put in, but how lite can you make it and still perform the functions. So @ echo off ping 1.4.1.4 >a.txt findstr /m "Request timed out" a.txt if %errorlevel%%==0 ( echo Save our nets!!! ) pause |
You need to use GOTO :toast:
EDIT: I would write an example.. but I'm off to bed. If you are still having problems tomorrow. I'll chime in. :toast: Steevo is on the right track! :toast: |
Okay... getting confused, Sorry I'm a noob programmer.
I've copied Steevo code and tried to modify it to suit my requirements and it isn't working. I presume I'm suppose to use the goto command Code:
@echo offI just realized i'm going to need to make the bat files create text files. edit okay simple fix would be to put del *.txt which would delete all text files and pretty much refresh it all the time at the beginning. |
Just reuse the same name and it will overwrite the files each time the batch is run.
|
you would be better off writing something in c++ or even VB
batch file != programming batch files are extremely limited |
You could install Cygwin and use BASH which is much more capable of doing what you're describing. I've actually written a script that does something like this using Ruby, where it takes in a list of IPs and returns a list of connected or disconnected users in either easy to read or XML format. Maybe something like that is what you're looking for? This is unmodified but might suit your purposes on a POSIX machine with BASH and Ping.
Code:
#!/usr/bin/ruby1.9.1 |
1 Attachment(s)
I usually don't like doing all the work for someone.. but I thought this project would be fun! Plus, I wanted to show the power of a batch file! hehehe There's a lot of easier languages out there and we are all quick to say, "Do it in vb or c# or so on". ...But Some times it's good to write a batch file just because.. hehehe
Code:
@ECHO off |
Man deserves credit
|
Quote:
|
I really appreciate it, your 50x better than mine.
I never mean't for someone to write the entire code just point me in the right direction. May I ask for me to add more sites do I just add more set like below? SET site3=www.hotmail.com SET site4=www.awesomer.com edit: sorry just read the code carefully, need to lots of copy paste. Thanks all! |
Quote:
Code:
::======================================================== |
Ok... Noob question
How do I make Mindweaver's script create a folder where the bat file is. eg. we have the bat file on a usb g:\nettest.bat. So the logs save on g:\ instead of c:\. I tried changing SET drive to = \ but that just breaks the entire script. |
SET drive=g:\nettest
and make sure you replicate the folder |
Sorry, I must of not made that clear.
I meant that the value would be a variable depending on where you run the bat file from. the usb or the file may not be on g: it could be e: or f:. I don't know if that made any sense..... |
Quote:
|
| All times are GMT. The time now is 02:56 AM. |
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.