You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
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.5
unpublished
latest
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.

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

License

The Unlicense

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 without prefixes.

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 10 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