Computing.Net > Forums > Disk Operating System > Batch files and testing connections

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch files and testing connections

Reply to Message Icon

Name: Sandy - a babe abroa
Date: May 9, 2001 at 03:29:04 Pacific
Comment:

Does anyone know how to do any of the following.

How to test if a modem is already in use and then exit the batch program if it is.

or

Ping an IP address, if there is no response then exit the batch program.

If anyone can help you will be my friend for life. promise........




Sponsored Link
Ads by Google

Response Number 1
Name: DoOMsdAY
Date: May 9, 2001 at 03:57:30 Pacific
Reply:

Number two is relatively simple. Use ping with whatever parameters you wish (ie. only one ping versus the usual four and of course the DNS name or IP address), then check the errorlevel to see if it was successful. Example:

ping someone
echo %errorlevel%

Now, try one you know will work and one you know will fail and see what is echo'ed each time. With any luck, they'll be two different numbers. They were on the NT machine I wrote this for for someone some time ago. However I think they were the same for them on a 9x machine. If they *are* different, then replace the echo with an if check for the bad value (always check for the highest possible value first with Batch if's) and a goto. Example:

ping someaddress
if errorlevel=1 goto error
echo we were successful!
goto end

:error
echo we failed!

:end

If they are the same, you could probably do it with redirection and find. Example:

ping someone > ping.txt
find "timed out" ping.txt

The above is essentially pseudocode though as I ceased Batch programming right as I began to learn find.com.


0

Response Number 2
Name: Sandy
Date: May 9, 2001 at 04:01:54 Pacific
Reply:

Thanks for your help.

You are now my very best friend. I will let you know how I get on.


0

Response Number 3
Name: Sandy - Babe abroad
Date: May 9, 2001 at 04:17:03 Pacific
Reply:

Ok, I tried to get the error level and it was the same value for a good and bad ping. The value was always 'zero'. This may mean that I can't do it on NT.

Do you have any other methods that I could try.

...........


0

Response Number 4
Name: Sandy
Date: May 9, 2001 at 04:46:03 Pacific
Reply:

I tried your 'find' solution and then tested the error level. This works perfectly.

Many thanks for your help on this one.

Regards
Sandy - Babe abroad


0

Response Number 5
Name: DoOMsdAY
Date: May 9, 2001 at 09:30:20 Pacific
Reply:

Oh good. The errorlevel with ping should have worked for NT. I was doing it on my NT Server machine. Wonder if I typed something wrong... Glad to hear you got it to work nonetheless. :)


0

Related Posts

See More



Response Number 6
Name: tsuji
Date: May 9, 2001 at 10:03:07 Pacific
Reply:

quote (take away =)

if errorlevel 1 goto error

unquote


0

Response Number 7
Name: DoOMsdAY
Date: May 9, 2001 at 19:33:59 Pacific
Reply:

That'd be it. Thanks tsuji. :)


0

Sponsored Link
Ads by Google
Reply to Message Icon

product key Batch files at shutdown



Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Batch files and testing connections

Batch files and system memory? www.computing.net/answers/dos/batch-files-and-system-memory/2820.html

Read batch file and write in a Text www.computing.net/answers/dos/read-batch-file-and-write-in-a-text/16653.html

batch file question www.computing.net/answers/dos/batch-file-question/3271.html