Skip to content

Instantly share code, notes, and snippets.

@futjikato
Created January 23, 2013 20:53
Show Gist options
  • Save futjikato/4613044 to your computer and use it in GitHub Desktop.
Save futjikato/4613044 to your computer and use it in GitHub Desktop.
Small NodeJs Script to log a ping command ( windows ) with a timestamp
var spawn = require('child_process').spawn,
fs = require('fs');
var logFile = fs.createWriteStream("pingtest.txt", {flags:"w",mode:0777});
var pingCmd = spawn("ping", ["-t", "google.de"]);
var tmp = "";
pingCmd.stdout.on("data", function(buffer){
tmp += buffer.toString();
if(tmp.indexOf("Antwort") != -1) {
var d = new Date();
var timestamp = d.getDay() + "." + (d.getMonth()+1) + "." + d.getFullYear() + " - " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
tmp = tmp.replace("Antwort", timestamp + " -- Antwort");
logFile.write(tmp, 'binary');
tmp = "";
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment