sir ..
there is also a much easier way to do it without using any regexp .... just
uses the 'os' and 'fs' module
although even the os package can be eliminated as well
just have a look at this snippet
*#!/usr/bin/env node*
*var os=require('os');*
*var fs=require('fs');*
*var IFaces=os.networkInterfaces();*
*// one glitch about os.networkInterfaces() is that it only displays
interfaces that are active*
*// any interface that is not active or brought down in the system shall
not be displayed nor listed. *
*// to do this without the usage of os.networkInterfaces is either read the
/proc/net/dev and do regext or either issue a stream command with filters
to list interfaces *
*// or you may have it the simplest ever is to list the contents of
directory in /sys/class/net*
*// this shall give you a entry list of all network devices configured and
present (active/notactive) on the system *
*
*
*Object.keys(IFaces).forEach(function(value,idx){*
* //idx is the index counter starts with 0 *
* //value is the interface name *
* //you can get the array list of interface ip addresses associated
with the interface *
* //by issuing *
*
*
* var Addresses=IFaces[value];*
* console.log(value +' holds ',Addresses);*
*
*
* // note this does not give you the subnet mask nor broadcast nor
any of the like *
* // so there is always a match to do "ip add sh dev ${dev}" and
regexp to get whatever you need *
* // anyhow we are interested in getting tx_bytes and rx_bytes
counters *
* // we already have our interface as in value and the rest is very
much easy *
* // if you notice reading /sys/class/net*
*});*
*
*
*/**
* *Just for being fair with my packages and to do list all network IFaces i
prefer doing the later method and execlude the os.networkInterfaces()
package*
*thus i shall be reading the directory listing instead *
* **
* *in this case we can omit the whole os module *
* */*
*fs.readdir('/sys/class/net',function(err,IFaces){*
* if(err) {*
* process.exit(1);*
* }else{*
* // IFaces holds an array list of all network Interfaces in
the system *
* IFaces.forEach(function(IFace){*
* var
Tx_Bytes=fs.readFileSync('/sys/class/net/'+IFace+'/statistics/tx_bytes');*
* var
Rx_Bytes=fs.readFileSync('/sys/class/net/'+IFace+'/statistics/rx_bytes');*
* console.log(IFace+ '\n\tTX :'+Tx_Bytes+'\n\tRX
:'+Rx_Bytes+'\n##');*
*
*
* });*
* }*
*
*
*});*
Much Regards
On Mon, Aug 26, 2013 at 11:36 AM, Faysal Banna <[email protected]> wrote:
> You're welcome ...
> hope it came in handy
>
> much regards
>
> Faysal Banna
> Meteorological Services
> Rafic Harriri International Airport
> Beirut - Lebanon
> Mob: +961-3-258043
>
> On 08/25/2013 11:15 PM, Ashutosh Das wrote:
>
> Thnx degreane :)
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
============================
Faysal Banna
Meteorological Services
Rafic Harriri International Airport
Beirut - Lebanon
Mob: +961-3-258043
=============================
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.