Solved Continuous Internet Connection Monitor - DOS bat

December 16, 2013 at 10:39:56
Specs: Windows Vista 64bit, SP2, , Quad Core, 8 gig
I need help in creating a DOS bat that will continuously monitor my internet connection and only append a Internetstatus.txt file if there is an error message, that will list the "Date/Time" stamp followed by the "URL" and finally a message, "...Connection Failed". The script will re-run every 15 seconds.
Thanks in advance for any assistance you may offer,
Don

Here is my logic:
Ping my Wi-Fi router 192.168.0.1
If no connection
Append Internetstatus.txt file with "Date/Time" "URL" "Wi-Fi Router Connection Failed"
Else
Ping my Cable Modem XXX.XXX.XXX.XXX
If no connection
Append Internetstatus.txt file with "Date/Time" "URL" Cable Modem Connection Failed"
Else
Ping my Internet Service Provider's Server XXX.XXX.XXX.XXX
If no connection
Append Internetstatus.txt file with "Date/Time" "URL" "ISP Connection Failed"
Else
Ping my DNS Server XXX.XXX.XXX.XXX
If no connection
Append Internetstatus.txt file with "Date/Time" URL" "DNS Server Connection Failed"
Else
Ping GOOGLE.com
If no connection
Append Internetstatus.txt with "Date/Time" "URL" Google Connection Failed"

Wait 14 seconds and restart this process


See More: Continuous Internet Connection Monitor - DOS bat

Report •

#1
December 17, 2013 at 21:36:10
✔ Best Answer
Sorry for this non-answer, but I would start pinging from top down, to save overhead (not that it amounts to much, but...). I would ping Google first. THEN: If that succeeds, then presumably you won't need to ping the underlings, as they are all awake and doing their jobs and your program can sleep., ELSE: Then I would work downwards from there if Google failed: DNS, then ISP, etc.
Altenatively, there is an "event-driven" option for schtasks on win7+, but not sure about Vista, which will run a task based on events (use switch: /create /MO ONEVENTS: "Xpath event query string") which would be ideal for your purposes, but that's all I know at this point, not having worked much with seven. Use Google "xpath event query string" or wait for someone competent (Razor, anyone? hint?) to help here. I figure if any live TCP/IP connection drops, an event would be triggered, and this setup would save a lot of overhead of constanly monitoring tcip connections "manually". Meantime, I'm curious myself, so I'll keep up.

message edited by nbrane


Report •

#2
December 18, 2013 at 04:35:49
I apologize, for the lack of some very important information. The batch file will not be run on the Vista PC, but on my Home Control PC which happens to be an aged tried and proven Dell Optiplex 286 PC that has been running 24/7 for the last 18 years. It sits idle most of the time, so the process will not affect the speed.

The inverting of the ping sequence makes so much more sense. Thank you..

I have tried a few attempts to start the writing of the ping process, by cutting and pasting individual parts of various batches I found. With no luck. I could not get past the first line, although I was able to get it to save the date stamp and a message, but the rest is over my head.

The reason for this request is an ongoing battle with Brighthouse over my cable connection, both internet and TV. I will tackle the internet connection first, which may fix the TV one also. They have replaced modems, cable drop, found water in a node, but nothing to totally eliminate the issues. I constantly get messages of "Connection Dropped". I also found complaints online regarding my D-Link DIR-655 wireless router indicating that there are issues with dropping connections. So, I figure if I can isolate where the problem is, I can take the file with times and errors back to the Data manager at Brighthouse and have them look back through their data to see what is happening, of if it is the D-Link modem, I can replace that. I have seen the Brighthouse router rebooting several times.

I am totally frustrated.

Thanks for your input

Don



Report •

#3
December 19, 2013 at 13:57:18
Ok, so I should assume you're using "paleo-batch" (pre-xp, or "DOS")? That's always a challenge, especially after getting used to all the "modern" conveniences of the up-to-date batch script. If I'm correct, you might try this. I had to dust off my old computer, and also blow the dust out of my brain-cells, but here you go:

@echo off
:top
set ip=google.com
set ret=2
:1
ping -n 1 -w 2000 %ip% | find /i "request timed out">nul
if not ERRORLEVEL 1 goto :err
goto :%ret%
:2
set ret=3
set ip=192.168.0.51
goto :1
:3
set ret=xit
set ip=192.168.0.2
goto :1

:err
echo.|date | find /i "Current">> connlog.txt
echo.|time | find /i "Current">> connlog.txt
echo %ip%>>connlog.txt
goto :%ret%

:xit
ping -n 1 -w 15000 0.0.0.1>nul
goto :top

message edited by nbrane


Report •

Related Solutions

#4
December 20, 2013 at 08:57:37
Thank you very much nbrane. All worked fine except the logging of the date time stamp, it just saved the IP address. I added %date% %time%between echo and %ip% and it workes fine. Now I can see what is happening. Will keep you informed.
Thanks again
Don

Report •

#5
December 20, 2013 at 13:36:59
Ah. My testing system (win-ME) didn't support %date% or %time% - that's why there were no percents around them. You must be using a "current" OS since they're supported. (So, my convoluted code probably did a lot of dancing around needlessly) My actual error was in using "Current" instead of /i "current" for the "find", which would probably have worked. I fixed that in my posted script. You could also clean up your output by:
echo %date% %time% %ip%>>connlog.txt

message edited by nbrane


Report •

Ask Question