Skip to content

Instantly share code, notes, and snippets.

@greyblue9
Created February 2, 2014 15:18
Show Gist options
  • Save greyblue9/8769817 to your computer and use it in GitHub Desktop.
Save greyblue9/8769817 to your computer and use it in GitHub Desktop.
<h1>Get LAN Clients<h1> <h2>A NodeJs-based command-line utility</h2> &copy; 2014 by David Reilly <hr/> Name of file: <span style="font-style: monospace">get_lan_clients.js</span>
/**
*
* get_lan_clients.js
*
* Outputs a parser-friendly list of LAN clients known by the local router.
*
* Dependencies:
* "request" module
* - install by issuing command 'npm install request'
*
* Usage:
* > node get_lan_clients.js [gatewayip]
*
* gatewayip The IP address of the LAN's default gateway/router,
* assumed to be 192.168.1.1 by default.
*
*
* Supported router/gateway hardware:
* TEW-639GR (TrendNet N300 Wireless Gigabit Router)
* - tested on Firmware v3.1.3.0 (dated 24-Aug-2012)
*
*/
(function() {
var protocol = 'http';
var gatewayIp = '192.168.1.1';
var urisByFunction = {
dhcpClientList: '/internet/dhcpcliinfo.asp'
};
/**
* Build a URL given a protocol, host, and URI.
* @param proto Protocol (either 'http' or 'https')
* @param hostOrIp The hostname/domain or IP address of the server, as
* accessible from the box running this script
* @param uri Resource URI on server
* @returns {string} Full URL to resource with specified protocol
*/
var getUrl = function(proto, hostOrIp, uri) {
return proto+'://'+hostOrIp+uri;
}
var getGatewayUrl = function(uri) {
return getUrl(protocol, gatewayIp, uri);
}
/**
* Module used to facilitate HTTP(s) requests
* @type {request|exports}
*/
var request = require('request');
var getGatewayUrl = getGatewayUrl(urisByFunction.dhcpClientList);
request('http://192.168.1.1', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Print the google web page.
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment