Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
JavaScript library to gather information for an ip using https://ipdata.co.
JavaScript library that can be used in a web browser or Node.js application to gather information for an IP address using https://ipdata.co.
Table of Contents
$ npm install ipdata
Import the library.
import IPData from 'ipdata';
Note: If you are using require()
then you will need to use the default value exported from the library.
const IPData = require('ipdata').default;
Create an instance of the IPData
class and pass your api key for IPData as the first parameter.
const ipdata = new IPData('<apiKey>');
The library will cache 4096 ip addresses responses for 24 hours using a LRU cache by default. You can configure the cache by passing an object as the second paramenter.
const cacheConfig = {
max: 1000, // max size
maxAge: 10 * 60 * 1000, // max age in ms (i.e. 10 minutes)
};
const ipdata = new IPData('<apiKey>', cacheConfig);
Note: To disable the cache pass -1
as the maxAge
.
const cacheConfig = {
maxAge: -1, // disable the cache
};
const ipdata = new IPData('<apiKey>', cacheConfig);
The library will lookup the ip address of the host computer if no ip address is provided.
ipdata.lookup()
.then(function(info) {
// info.ip === '<hostcomputerip>'
// ...
});
You can pass an ip address as the first parameter to the lookup()
method to lookup information about the ip address using IPData.
const ip = '1.1.1.1';
ipdata.lookup(ip)
.then(function(info) {
// info.ip === 1.1.1.1
// ...
});
You can specify only a select field to be returned when looking up an ip address by passing a field as the second parameter to the lookup()
method.
const ip = '1.1.1.1';
const selectField = 'ip';
ipdata.lookup(ip, selectField)
.then(function(info) {
// info.select_field === 1.1.1.1
// ...
});
You can specify only certain fields to be returned when looking up an ip address by passing an array of fields as the third parameter to the lookup()
method.
const ip = '1.1.1.1';
const fields = ['ip', 'city'];
ipdata.lookup(ip, null, fields)
.then(function(info) {
// ...
});
You can lookup multiple ip addresses with one API call using the bulkLookup()
method.
const ips = ['1.1.1.1', '1.0.0.1'];
ipdata.bulkLookup(ips)
.then(function(info) {
// info[0].ip === 1.1.1.1
// ...
});
You can specify only certain fields to be returned when looking up multiple ip addresses by passing an array of fields as the second parameter to the bulkLookup()
method.
const ips = ['1.1.1.1', '1.0.0.1'];
const fields = ['ip', 'city'];
ipdata.bulkLookup(ips, fields)
.then(function(info) {
// ...
});
FAQs
JavaScript library to gather information for an ip using https://ipdata.co.
The npm package ipdata receives a total of 6,944 weekly downloads. As such, ipdata popularity was classified as popular.
We found that ipdata demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.