1.0.2 • Published 7 years ago
node-ip-client v1.0.2
node-ip-client
Official IP Lookup API Node JS SDK by www.ip-lookups.com
This SDK implements the REST API documented at https://www.ip-lookups.com/en/api-docs
For SDKs in other programming languages, see https://www.ip-lookups.com/en/sdks
Requirements
- node-rest-client
Installation with npm
npm install node-ip-client
Usage Client
#!/usr/bin/env node
var IpLookupClient = require("../lib/node-ip-client");
var client = new IpLookupClient(
'username',
'password'
);
/**
* Submits a synchronous IP Lookup request. The IP is queried in real time and results presented in the response body.
*
* @param callback - callback function(response)
* @param ip - An IPv4 or IPv6 address
* @param engine - An optional engine assignment, see: http://www.ip-lookups.com/en/data-source-engines
* @param storage - An optional storage assignment, see: http://www.ip-lookups.com/en/storages
* @returns {*}
*
* Return example: {"success":true,"results":{"context":{"id":"7044a161c662","ip":"23.105.134.61","state":"COMPLETED","storage":"SYNC-API-2017-02","engine":"IV1","interface":"Sync API","cost":"0.01000","timeStamp":"2017-02-18 18:27:50.267098+08"},"geolocation":{"country":"United States","region":"Arizona","countryCode":"US","regionCode":"AZ","city":"Phoenix","zip":"85054","latitude":"33.67480","longitude":"-111.95190","radius":1000,"timeZone":"America\/Phoenix","averageIncome":null,"populationDensity":null,"dmaCode":753},"network":{"connectionType":"HOSTING","asn":"15003","asnOrganization":"Nobis Technology Group, LLC","isp":"Nobis Technology Group, LLC","ispOrganization":"Nobis Technology Group, LLC","domain":"ubiquity.io","registeredCountry":"United States","registeredCountryCode":"US","isRoutable":true},"threatIntelligence":{"threatLevel":"VERY_HIGH","threatIntelligenceScore":"1.00000","genericBlacklistMatch":true,"proxyBlacklistMatch":true,"torBlacklistMatch":false,"vpnBlacklistMatch":true,"malwareBlacklistMatch":false,"spywareBlacklistMatch":false,"hijackBlacklistMatch":false,"crawlerBlacklistMatch":false,"botBlacklistMatch":false,"spamBotBlacklistMatch":false,"exploitBotBlacklistMatch":false,"dshieldBlacklistMatch":false}}}
*/
client.submitSyncLookup(function(response) {
console.log(response);
}, '85.10.208.227');
/**
* Submits asynchronous IP Lookups containing up to 1,000 IPs per request. Results are sent back asynchronously to a callback URL on your server. Use \VmgLtd\IpCallbackHandler to capture them.
*
* @param callback - callback function(response)
* @param ips - A list of IPv4 or IPv6 addresses
* @param engine - An optional engine assignment, see: http://www.ip-lookups.com/en/data-source-engines
* @param storage - An optional storage assignment, see: http://www.ip-lookups.com/en/storages
* @returns {*}
*
* Return example: {"success":true,"results":{"acceptedIps":[{"id":"58cc4f7c4afc","ip":"85.10.208.227"},{"id":"d40499b8605c","ip":"85.10.208.228"},{"id":"8bdc66d4ce52","ip":"85.208.221.221"}],"rejectedIps":[],"acceptedIpCount":3,"rejectedIpCount":0,"totalCount":3,"cost":0.03,"storage":"ASYNC-API-2017-02","engine":"IV1"}}
*/
client.submitAsyncLookup(function(response) {
console.log(response);
}, ['85.10.208.227', '85.10.208.228']);
/**
* Sets the callback URL for asynchronous lookups. Read more about the concept of asynchronous IP lookups @ http://www.ip-lookups.com/en/asynchronous-ip-lookup-api
*
* @param callback - callback function(response)
* @param url - callback url on your server
* @returns {*}
*
* Return example: {"success":true,"results":{"url":"http:\/\/user:pass@www.your-server.com\/path\/file"}}
*/
client.setAsyncCallbackUrl(function(response) {
console.log(response);
}, 'http://user:pass@www.your-server.com/path/file');
/**
* Returns the remaining balance (EUR) in your account.
*
* @param callback - callback function(response)
* @returns {*}
*
* Return example: {"success":true,"results":{"balance":"5878.24600"}}
*/
client.getBalance(function(response) {
console.log(response);
});
Usage Callback Handler
#!/usr/bin/env node
var http = require('http');
var url = require("url");
var port = 8585;
var IpLookupClient = require("../lib/node-ip-client");
var client = new IpLookupClient();
http.createServer(function(request, response) {
if (request.url == '/favicon.ico') return;
var params = url.parse(request.url, true).query;
/**
* Parses an asynchronous IP Lookup callback and returns a JSON string with the results.
*
* @param params
* @returns {*}
*
* Params example: {"success":true,"results":[{"context":{"id":"3ac9069dc6e9","ip":"85.10.208.227","state":"COMPLETED","storage":"ASYNC-API-2017-02","engine":"IV1","interface":"Async API","cost":"0.01000","timeStamp":"2017-02-09 22:57:33.80855+08"},"geolocation":{"country":"Germany","region":"Bavaria","countryCode":"DE","regionCode":"BY","city":"Nuremberg","zip":"90455","latitude":"49.44780","longitude":"11.06830","radius":200,"timeZone":"Europe\/Berlin","averageIncome":null,"populationDensity":null,"dmaCode":null},"network":{"connectionType":"HOSTING","asn":"24940","asnOrganization":"Hetzner Online GmbH","isp":"Hetzner Online GmbH","ispOrganization":"Hetzner Online GmbH","domain":"your-server.de","registeredCountry":"Germany","registeredCountryCode":"DE","isRoutable":true},"threatIntelligence":{"threatLevel":"VERY_HIGH","threatIntelligenceScore":"1.00000","genericBlacklistMatch":false,"proxyBlacklistMatch":false,"torBlacklistMatch":false,"vpnBlacklistMatch":false,"malwareBlacklistMatch":false,"spywareBlacklistMatch":false,"hijackBlacklistMatch":false,"crawlerBlacklistMatch":false,"botBlacklistMatch":false,"spamBotBlacklistMatch":false,"exploitBotBlacklistMatch":false,"dshieldBlacklistMatch":false}}]}
*/
console.log(client.parseCallback(params));
response.writeHead(200);
response.write('OK');
response.end();
}).listen(port);
console.log("Callback Handler is listening on port " + port);
With that you should be ready to go!
Tests
The code contains annotations and you can find usage examples as tests in tests/
:
tests/test-client.js
tests/test-callback.js
Please refer to https://www.ip-lookups.com/en/sdks/nodejs for further documentation or send us an email to service@ip-lookups.com.
Support and Feedback
Your feedback is appreciated! If you have specific problems or bugs with this SDK, please file an issue on Github. For general feedback and support requests, send an email to service@ip-lookups.com.
Contributing
- Fork it ( https://github.com/vmgltd/ip-lookup-api-nodejs-sdk/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request