ip matching
Release 2.1.2

独立模块具有有关IPS的一些方便功能:
npm install --save ip-matching
# or
yarn add ip-matching附带其自己的内置打字稿声明,其中包含文档。
import { getMatch , IPMatch , IPSubnetwork , IPRange , matches } from 'ip-matching' ;
// matches(ip: string | IP, target: string | IPMatch): boolean;
matches ( '10.0.0.1' , '10.0.0.0/24' ) ; // true
matches ( '10.0.1.1' , '10.0.0.0/24' ) ; // false
matches ( 'abc::def' , 'abc:*::def' ) ; // true
matches ( 'abc::def' , 'abc:9::def' ) ; // false
matches ( '0001:2:3:4:5:6:7' , '1:2:3:4:5:6:7' ) ; // true
// getMatch returns an instance of
// IPv4, IPv6, IPRange, IPSubnetwork or IPMask, all extending IPMatch
const mySubnet : IPMatch = getMatch ( 'fefe::0001:abcd/112' ) ;
mySubnet . type ; // 'IPSubnetwork'
mySubnet instanceof IPSubnetwork ; // true
mySubnet instanceof IPMatch ; // true
mySubnet . toString ( ) ; // 'fefe::1:0/112'
mySubnet . matches ( 'FEFE::1:bbbb' ) ; // true
mySubnet . matches ( 'FEFE::2:bbbb' ) ; // false
mySubnet . equals ( new IPSubnetwork ( new IPv6 ( 'fefe::1:abcd' ) , 112 ) ) ; // true
mySubnet . getAmount ( ) ; // 65536
( mySubnet as IPSubnetwork ) . getLast ( ) . toString ( ) ; // 'fefe::1:ffff'
const myIp = new IPv6 ( 'a:0:0::B:0:C' ) ;
myIp . toString ( ) ; // 'a::b:0:c'
myIp . toLongString ( ) ; // 'a:0:0:0:0:b:0:c'
myIp . toFullString ( ) ; // '000a:0000:0000:0000:0000:000b:0000:000c'
new IPv6 ( '::ffff:a9db:*' ) . toMixedString ( ) ; // '::ffff:169.219.*.*'
const myRange = getMatch ( '10.0.0.0-10.1.2.3' ) as IPRange ;
myRange . convertToMasks ( ) . map ( ( mask : IPMask ) => mask . convertToSubnet ( ) . toString ( ) ) ;
// [ '10.0.0.0/16', '10.1.0.0/23', '10.1.2.0/30' ]
const mask1 = getMatch ( '10.0.1.0/255.0.255.0' ) as IPMask ;
const mask2 = getMatch ( '10.0.0.0/128.0.0.0' ) as IPMask ;
mask1 . isSubsetOf ( mask2 ) ; // true
mask2 . getAmount ( ) ; // 2147483648
getMatch ( 'a::abbc:1234/ffff::ff80:000f' ) . toString ( ) ; // 'a::ab80:4/ffff::ff80:f'注意: matches功能和所有无效输入的构造函数错误
您可以查看所有功能的测试代码或打字稿声明。
10.0.0.010.0.0.*甚至10.*.0.*2001:0db8:85a3:0000:0000:8a2e:0370:73342001:db8:85a3::8a2e:0370:7334或:: OR ::1或a::2001::*甚至2001::*:abc:*::ffff:127.0.0.1 (IPv4零件中不允许通配符)10.0.1*.0或2001::a*c10.0.0.0-10.1.2.32001::abc-2001::1:ffff10.0.0.0/162001::/12310.0.0.0/255.0.64.02001:abcd::/ffff:ff8:: IPMASK的toString()方法不会自动简化Eg /255.0.0.0至/8 ,即使这些方法是等效的。由于2.0.0,IPMASK随附了一种方法convertToSubnet()该方法在可能的情况下返回等效的ipsubnetwork,否则undefined 。
这是一些众所周知的类似NPM软件包,它们所缺乏的功能,反之亦然。在所有情况下,如果您认为它非常适合此模块,请随时请求新功能。
.ip6.arpa )并进行范围(分区)地址