GithubHelp home page GithubHelp logo

missinglink / netstat.js Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 6.0 254 KB

nodejs binding for netstat, just in case you felt the need to see what your network is up to.

JavaScript 99.74% CSS 0.26%

netstat.js's Introduction

netstat.js

A simple js wrapper for the netstat daemon.

Allows you to output network statistics in real-time through stdout or via a socketio server.

Output is available in json or as raw stdout lines.


Installing

$ npm install netstat --save

Note: you will need node and npm installed first.

The easiest way to install node.js is with nave.sh by executing [sudo] ./nave.sh usemain 0.10

You will need netstat installed, this is not a replacement for netstat; just a wrapper. On most unix-like systems it should be provided by default in the net-tools package.


Getting data from netstat

var netstat = require('netstat');

netstat.on( 'stdout', function( data ){
  process.stdout.write(
    JSON.stringify( netstat.parse( data ), null, 2 ) + '\n'
  );
});

netstat.on( 'stderr', function( err ) {
  process.stderr.write( err );
});

Example output:

[
  {
    "Proto": "tcp",
    "Recv-Q": "0",
    "Send-Q": "0",
    "Local-Address": "192.168.0.15:13887",
    "Foreign-Address": "95.91.245.60:29101",
    "State": "ESTABLISHED",
    "User": "1000",
    "Inode": "151487",
    "PID/Program-name": "9738/spotify"
  },
  {
    "Proto": "tcp",
    "Recv-Q": "0",
    "Send-Q": "0",
    "Local-Address": "192.168.0.15:13887",
    "Foreign-Address": "148.177.128.81:21404",
    "State": "ESTABLISHED",
    "User": "1000",
    "Inode": "152049",
    "PID/Program-name": "9738/spotify"
  }
]

Binary version

You can install netstatjs globally by executing [sudo] npm install -g netstat

If you installed locally then you can execute it like this ./node_modules/netstat/bin/netstatjs --help

The binary version has a few nice features like daemonizing & sending json stats to stdout or via socketio.

peter@edgy:/var/www$ netstatjs --help

  Usage: netstatjs [options]

  Options:

    -h, --help             output usage information
    -V, --version          output the version number
    -s, --socketio [port]  bind socketio to port and stream stats in json
    -j, --json [indent]    pipe json stats to stdout/stderr
    -r, --raw              pipe raw stats to stdout/stderr

Examples

More examples can be found in /bin/command/*.

Status

This module is usable but not yet feature rich, netstat provides heaps more cool features that are not yet supported. Please star, fork and pull request if you find this useful.

License

Released under the MIT(Poetic) Software license

This work 'as-is' we provide.
No warranty express or implied.
Therefore, no claim on us will abide.
Liability for damages denied.

Permission is granted hereby,
to copy, share, and modify.
Use as is fit,
free or for profit.
These rights, on this notice, rely.

Bitdeli Badge

netstat.js's People

Contributors

missinglink avatar bitdeli-chef avatar

Stargazers

Rudys85 avatar Dariusz Filipiak avatar Ian G avatar Colt Evil avatar Rick Blundell avatar Yorkie Makoto avatar Adam Elsodaney avatar Matteo Figus avatar  avatar  avatar Fabrizio Moscon avatar  avatar

Watchers

 avatar Rick Blundell avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.