What is public-ip?
The public-ip npm package allows you to get your public IP address (IPv4 or IPv6) from different services. It supports both IPv4 and IPv6, and it can be used in Node.js environments.
What are public-ip's main functionalities?
Get IPv4 Address
This feature allows you to get your public IPv4 address. The code sample demonstrates how to use the public-ip package to fetch and log the IPv4 address.
const publicIp = require('public-ip');
(async () => {
console.log(await publicIp.v4());
})();
Get IPv6 Address
This feature allows you to get your public IPv6 address. The code sample demonstrates how to use the public-ip package to fetch and log the IPv6 address.
const publicIp = require('public-ip');
(async () => {
console.log(await publicIp.v6());
})();
Get IP Address with Options
This feature allows you to get your public IP address with additional options. The code sample demonstrates how to use the public-ip package to fetch the IPv4 address using only HTTPS services.
const publicIp = require('public-ip');
(async () => {
console.log(await publicIp.v4({ onlyHttps: true }));
})();
Other packages similar to public-ip
ipify
The ipify package is another tool to get your public IP address. It is similar to public-ip but focuses on using the ipify service to fetch the IP address. It supports both IPv4 and IPv6.
external-ip
The external-ip package provides a way to get your public IP address by querying multiple services and returning the first successful response. It offers more flexibility in terms of service selection compared to public-ip.
public-ip-cli
The public-ip-cli package is a command-line interface for the public-ip package. It allows you to fetch your public IP address directly from the command line, making it convenient for quick checks without writing code.
public-ip
Get your public IP address - very fast!
Queries the DNS records of OpenDNS which has an entry with your IP address.
Install
$ npm install --save public-ip
Usage
const publicIp = require('public-ip');
publicIp.v4().then(ip => {
console.log(ip);
});
publicIp.v6().then(ip => {
console.log(ip);
});
API
publicIp.v4()
Returns a Promise for your public IPv4 address.
publicIp.v6()
Returns a Promise for your public IPv6 address.
Related
License
MIT © Sindre Sorhus