Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Batch File Help


  • Please log in to reply
8 replies to this topic

#1 tenz

tenz

  • Members
  • 105 posts
  • OFFLINE
  •  
  • Local time:11:53 PM

Posted 12 July 2011 - 08:41 PM

Hey Guys, here's the situation:

I am having internet outages and I want to monitor when it is happening. the easiest thing that i thought of was scheduling a batch file to ping an external ip then internal ip, and output the results to a text file. Review these files and figure out general time frames of the outages.

This batch worked, but every time i ran it it overwrote the last run. What I would like it to do is to name the output text file in a series, eg... pingtest1.txt, pingtest2.exe etc... What would also work would be to have the output append the text file, and i can add a "time /T" to keep track of when things happen

What can I add to the batch to achieve something like this?

I am using windows 7, but i have a linux system as well if a batch for that is easier.

Thanks
Tenz

Edited by tenz, 12 July 2011 - 08:43 PM.


BC AdBot (Login to Remove)

 


#2 Andrew

Andrew

    Bleepin' Night Watchman


  • Moderator
  • 8,257 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:Right behind you
  • Local time:08:53 PM

Posted 12 July 2011 - 08:45 PM

Use the append (">>") operator in your redirection of output rather than ">":

ping 8.8.8.8 >> C:\pingtest.log


#3 tenz

tenz
  • Topic Starter

  • Members
  • 105 posts
  • OFFLINE
  •  
  • Local time:11:53 PM

Posted 12 July 2011 - 08:53 PM

Thanks... As you can tell im new to scripting.

I appreciate it!

-Tenz

#4 Andrew

Andrew

    Bleepin' Night Watchman


  • Moderator
  • 8,257 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:Right behind you
  • Local time:08:53 PM

Posted 12 July 2011 - 08:58 PM

:thumbup2:

For a little extra usefulness:

echo %date% %time% >> C:\pingtest.log && ping 8.8.8.8 >> C:\pingtest.log && echo ===============================================

That will give you a log file similar to this:

Tue 07/12/2011 18:52:29.75

Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=73ms TTL=50
Reply from 8.8.8.8: bytes=32 time=73ms TTL=50
Reply from 8.8.8.8: bytes=32 time=73ms TTL=50
Reply from 8.8.8.8: bytes=32 time=72ms TTL=50

Ping statistics for 8.8.8.8:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 72ms, Maximum = 73ms, Average = 72ms
====================================
Tue 07/12/2011 18:52:33.80

Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=72ms TTL=50
Reply from 8.8.8.8: bytes=32 time=73ms TTL=50
Reply from 8.8.8.8: bytes=32 time=73ms TTL=50
Reply from 8.8.8.8: bytes=32 time=73ms TTL=50

Ping statistics for 8.8.8.8:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 72ms, Maximum = 73ms, Average = 72ms
====================================
Tue 07/12/2011 18:52:54.26

Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=72ms TTL=50
Reply from 8.8.8.8: bytes=32 time=73ms TTL=50
Reply from 8.8.8.8: bytes=32 time=72ms TTL=50
Reply from 8.8.8.8: bytes=32 time=73ms TTL=50

Ping statistics for 8.8.8.8:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 72ms, Maximum = 73ms, Average = 72ms
====================================


FTR, 8.8.8.8 is one of Google's DNS servers. If it's down, then the internet probably exploded.

#5 tenz

tenz
  • Topic Starter

  • Members
  • 105 posts
  • OFFLINE
  •  
  • Local time:11:53 PM

Posted 12 July 2011 - 09:05 PM

Thanks, Im going to use that... i was using 2 lines,

time /T >> "c:\users\tenz\documents\my dropbox\ping results\ping.log"
ping 8.8.8.8 >> "c:\users\tenz\documents\my dropbox\ping results\ping.log"

which gave me the output of
10:04 PM

Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=16ms TTL=52
Reply from 8.8.8.8: bytes=32 time=15ms TTL=52
Reply from 8.8.8.8: bytes=32 time=15ms TTL=52
Reply from 8.8.8.8: bytes=32 time=25ms TTL=52

Ping statistics for 8.8.8.8:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 15ms, Maximum = 25ms, Average = 17ms


But yours is better with the date in there also.

Double thanks Man!!!

-Tenz

#6 Andrew

Andrew

    Bleepin' Night Watchman


  • Moderator
  • 8,257 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:Right behind you
  • Local time:08:53 PM

Posted 12 July 2011 - 09:08 PM

:grinner:

#7 Didier Stevens

Didier Stevens

  • BC Advisor
  • 2,672 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:05:53 AM

Posted 13 July 2011 - 05:46 AM

the easiest thing that i thought of was scheduling a batch file to ping an external ip then internal ip, and output the results to a text file.

Can you tell us why you ping the internal IP address? Is it to differentiate between an Internet outage and a LAN outage?
If this is the reason, I recommend you take a look at the tracert command (tracert on Windows and traceroute on Linux).

tracert works like ping, but you'll get a reply from each "gateway" on the way to your destination.
So if you can't reach your destination, tracert will tell you exactly how far you can get with your connection.

More tracert details on Wikipedia: https://secure.wikimedia.org/wikipedia/en/wiki/Traceroute

Didier Stevens
http://blog.DidierStevens.com
http://DidierStevensLabs.com

SANS ISC Handler
Microsoft MVP 2011-2016 Consumer Security, Windows Insider MVP 2016-2018
MVP_Horizontal_BlueOnly.png

 

If you send me messages, per Bleeping Computer's Forum policy, I will not engage in a conversation, but try to answer your question in the relevant forum post. If you don't want this, don't send me messages.

 

Stevens' law: "As an online security discussion grows longer, the probability of a reference to BadUSB approaches 1.0"


#8 JosiahK

JosiahK

  • Members
  • 269 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:04:53 AM

Posted 13 July 2011 - 02:41 PM

More tracert details on Wikipedia: https://secure.wikimedia.org/wikipedia/en/wiki/Traceroute

Someone else who uses the HTTPS-everywhere Fx addon?
Quod non mortiferum, fortiorem me facit.
I don't read minds. Please help everyone by answering any questions and reporting on the results of any instructions. Query any concerns and explain problems or complications.

#9 Didier Stevens

Didier Stevens

  • BC Advisor
  • 2,672 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:05:53 AM

Posted 14 July 2011 - 03:26 AM


More tracert details on Wikipedia: https://secure.wikimedia.org/wikipedia/en/wiki/Traceroute

Someone else who uses the HTTPS-everywhere Fx addon?

Yup!

Didier Stevens
http://blog.DidierStevens.com
http://DidierStevensLabs.com

SANS ISC Handler
Microsoft MVP 2011-2016 Consumer Security, Windows Insider MVP 2016-2018
MVP_Horizontal_BlueOnly.png

 

If you send me messages, per Bleeping Computer's Forum policy, I will not engage in a conversation, but try to answer your question in the relevant forum post. If you don't want this, don't send me messages.

 

Stevens' law: "As an online security discussion grows longer, the probability of a reference to BadUSB approaches 1.0"





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users