Created
February 2, 2014 15:18
-
-
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>
© 2014 by David Reilly
<hr/>
Name of file: <span style="font-style: monospace">get_lan_clients.js</span>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* 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