@kristall/get-ips
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

Get IPs

This code is used to get the IP's of the network device using JavaScript.

Installation

Use your favorite package manager to install the dependencies (npm, yarn , pnpm).

pnpm add @kristall/get-ips

Usage

import { getIPs } from '@kristall/get-ips';

const ips = getIPs();

By default the function will search for IPv4 addresses, but you can also search for IPv6 addresses.

import { getIPs } from '@kristall/get-ips';

// IPv6
const ipv6Addresses = getIPs('ipv6');

// IPv4 - Both are the same
const ipv4Addresses = getIPs();
const ipv4AddressesDefault = getIPs('ipv4');

The function will return an array of strings with the IP's of the device as a NetworkInterfaceInfo from the os module of node.

Example of the return

[
  {
    address: '0.0.0.0',
    netmask: '255.255.255.0',
    family: 'IPv4',
    mac: '0a:0a:0a:0a:0a:0a',
    internal: false,
    cidr: '0.0.0.0/24'
  }
]

Readme

Keywords

none

Package Sidebar

Install

npm i @kristall/get-ips

Weekly Downloads

8

Version

0.0.8

License

ISC

Unpacked Size

15.5 kB

Total Files

6

Last publish

Collaborators

  • jaredmb