Ping using nodejs Javascript code

 




---------------------------------------------------------------

var ping = require('ping');

var chalk = require('chalk')

const fs = require('fs')

var http = require('http');





//// ping utility////

let config = fs.readFileSync('config.txt', 'utf-8')


const array_ = config.split("\r\n")






function pinserver(n) {

    let Hostentry = array_[n];

let hostEntry_ = Hostentry.split(' ');

// console.log(hostEntry_)

    

    ping.sys.probe(hostEntry_[0], function (isAlive) {



        var msg = isAlive ? 'host ' + hostEntry_[0] + ' is alive' : 'host ' + hostEntry_[0] + ' is dead';

        

        

        var status = msg.includes('is alive')

        if (status == true) {

            console.log(chalk.green(msg));

        } else {

            console.log(chalk.red(msg));

        }

        return msg;

    });



}



pinserver(1)

pinserver(2)

pinserver(3)

pinserver(4)

pinserver(5)

--------------------------------------------------------------------

Comments

Popular

icegate registration with dsc | Unable to execute PKI Component

MFS100 mantra driver installation and RD service

Repair Hikvision IP Camera | Cable color codding