A TypeScript utility for retrieving the public IPv4 and IPv6 addresses using the ipify API.
Use the package manager npm or yarn to install ip-address-retriever.
npm install ip-address-retriever
yarn add ip-address-retriever
import { IP } from 'ip-address-retriever';
// Retrieve IPv4 and IPv6 addresses
async function fetchIP(): Promise<void> {
try {
const ipv4: string = await IP.getIpv4();
const ipv6: string = await IP.getIpv6();
console.log('IPv4:', ipv4);
console.log('IPv6:', ipv6);
} catch (error) {
console.error('Error:', error);
}
}
fetchIP();
Returns a promise that resolves to the public IPv4 address of the client.
Returns a promise that resolves to the public IPv6 address of the client.
This package utilizes the ipify API for retrieving IP addresses