Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

toip

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

toip

Converts the IP addresses to their integer representation and vice versa.

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18
decreased by-18.18%
Maintainers
0
Weekly downloads
 
Created
Source

ToIp

A utility allowing an easy conversion between IP addresses and integers.

An IPv4 address is technically a 32-bit integer that is commonly represented by a string in the format 0.0.0.0. Similarly, IPv6 addresses are 128-bit integers that are commonly represented by a string in the format 0:0:0:0:0:0:0:0.

The ability to convert between these two representations make it easier to iterate over a large number of IP addresses.

Installation

npm install toip
yarn add toip
pnpm add toip

Usage

JavaScript example

const { toIPv4 } = require('toip');

console.log(toIPv4(0)); //prints out 0.0.0.0
console.log(toIPv4(1)); //prints out 0.0.0.1
console.log(toIPv4(4294967295)); //prints out 255.255.255.255

TypeScript example

import { toIPv4 } from 'toip';

console.log(toIPv4(0)); //prints out 0.0.0.0
console.log(toIPv4(1)); //prints out 0.0.0.1
console.log(toIPv4(4294967295)); //prints out 255.255.255.255

Functions

  • toIPv4(number) - Converts a number to an IPv4 address represented as string in format 0.0.0.0.
  • ipv4ToNumber(string) - takes in an IPv4 address represented as a string in format 0.0.0.0 and returns the number representation.
  • toIPv6(bigint) - Converts a number to an IPv6 address represented as string in format fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff or just :: for the shorthand representation.
  • ipv6ToNumber(string) - Converts an IPv6 address string and converts it to a bigint number.

Keywords

FAQs

Package last updated on 24 Jun 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc