Socket
Book a DemoInstallSign in
Socket

ip-address-validation

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

ip-address-validation

Validate IPv4 and IPv6 addresses with a fast JavaScript module.

1.0.0
unpublished
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

About

Description

This is a fast module for validating IPv4 and IPv6 addresses.

It's written in JavaScript with extreme efficiency and simplicity.

Explanation

A complete line-by-line code algorithm explanation is coming soon.

License

MIT License

Sponsor

Buy Me a Coffee | Cash App | Patreon | PayPal

Installation

Browser

git clone https://github.com/liamloads/javascript-ip-address-validation-module.git
<script src="ip-address-validation.js" type="text/javascript"></script>
<script type="text/javascript">console.log(ipAddressValidation('127.0.0.1'));</script>

Unix

cd
npm install ip-address-validation
const ipAddressValidation = require('ip-address-validation');
console.log(ipAddressValidation('127.0.0.1'));

Usage

Details

The module function accepts one IPv4 or IPv6 address argument.

IPv4 addresses are accepted with dotted x.x.x.x formatting without base conversion or subnet masking.

IPv6 addresses are accepted with long x:x:x:x:x:x:x:x, short x::x or translated x:x:x:x:x:x:x.x.x.x formatting.

The return value is a number with an IP address version of either 4 or 6.

If the argument isn't a valid IPv4 or IPv6 address, the return value is false.

Examples

console.log(ipAddressValidation('127.0.0.1'));
// 4

console.log(ipAddressValidation(' 127.0.0.1'));
// false

console.log(ipAddressValidation('127.0.0.1/32'));
// false

console.log(ipAddressValidation('127.0.0.1000'));
// false

console.log(ipAddressValidation('::1'));
// 6

console.log(ipAddressValidation(':::1'));
// false

console.log(ipAddressValidation('0000:0000:0000:0000:0000:0000:0000:0001'));
// 6

console.log(ipAddressValidation('0000:0000:0000:0001::127.0.0.1'));
// 6

console.log(ipAddressValidation('0000:0000:0000:0000:0001::127.0.0.1000'));
// false

console.log(ipAddressValidation('AB:ab::cd:CD'));
// 6

Keywords

algorithm

FAQs

Package last updated on 02 Aug 2022

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.