(function(){varr,t,n,e,i,o,a,s;t={},s=this,"undefined"!=typeofmodule&&null!==module&&module.exports?module.exports=t:s.ipaddr=t,a=function(r,t,n,e){vari,o;if(r.length!==t.length)thrownewError("ipaddr: cannot match CIDR for objects with different lengths");for(i=0;e>0;){if((o=n-e)<0&&(o=0),r[i]>>o!=t[i]>>o)return!1;e-=n,i+=1}return!0},t.subnetMatch=function(r,t,n){vare,i,o,a,s;null==n&&(n="unicast");for(oint)for(!(a=t[o])[0]||a[0]instanceofArray||(a=[a]),e=0,i=a.length;e<i;e++)if(s=a[e],r.kind()===s[0].kind()&&r.match.apply(r,s))returno;returnn},t.IPv4=function(){functionr(r){vart,n,e;if(4!==r.length)thrownewError("ipaddr: ipv4 octet count should be 4");for(t=0,n=r.length;t<n;t++)if(!(0<=(e=r[t])&&e<=255))thrownewError("ipaddr: ipv4 octet should fit in 8 bits");this.octets=r}returnr.prototype.kind=function(){return"ipv4"},r.prototype.toString=function(){returnthis.octets.join(".")},r.prototype.toNormalizedString=function(){returnthis.toString()},r.prototype.toByteArray=function(){returnthis.octets.slice(0)},r.prototype.match=function(r,t){varn;if(void0===t&&(r=(n=r)[0],t=n[1]),"ipv4"!==r.kind())thrownewError("ipaddr: cannot match ipv4 address with non-ipv4 one");returna(this.octets,r.octets,8,t)},r.prototype.SpecialRanges={unspecified:[[newr([0,0,0,0]),8]],broadcast:[[newr([255,255,255,255]),32]],multicast:[[newr([224,0,0,0]),4]],linkLocal:[[newr([169,254,0,0]),16]],loopback:[[newr([127,0,0,0]),8]],carrierGradeNat:[[newr([100,64,0,0]),10]],private:[[newr([10,0,0,0]),8],[newr([172,16,0,0]),12],[newr([192,168,0,0]),16]],reserved:[[newr([192,0,0,0]),24],[newr([192,0,2,0]),24],[newr([192,88,99,0]),24],[newr([198,51,100,0]),24],[newr([203,0,113,0]),24],[newr([240,0,0,0]),4]]},r.prototype.range=function(){returnt.subnetMatch(this,this.SpecialRanges)},r.prototype.toIPv4MappedAddress=function(){returnt.IPv6.parse("::ffff:"+this.toString())},r.prototype.prefixLengthFromSubnetMask=function(){varr,t,n,e,i,o,a;for(a={0:8,128:7,192:6,224:5,240:4,248:3,252:2,254:1,255:0},r=0,i=!1,t=n=3;n>=0;t=n+=-1){if(!((e=this.octets[t])ina))returnnull;if(o=a[e],i&&0!==o)returnnull;8!==o&&(i=!0),r+=o}return32-r},r}(),n="(0?\\d+|0x[a-f0-9]+)",e={fourOctet:newRegExp("^"+n+"\\."+n+"\\."+n+"\\."+n+"$","i"),longValue:newRegExp("^"+n+"$","i")},t.IPv4.parser=function(r){vart,n,i,o,a;if(n=function(r){return"0"===r[0]&&"x"!==r[1]?parseInt(r,8):parseInt(r)},t=r.match(e.fourOctet))returnfunction(){varr,e,o,a;for(a=[],r=0,e=(o=t.slice(1,6)).length;r<e;r++)i=o[r],a.push(n(i));returna}();if(t=r.match(e.longValue)){if((a=n(t[1]))>4294967295||a<0)thrownewError("ipaddr: address outside defined range");returnfunction(){varr,t;for(t=[],o=r=0;r<=24;o=r+=8)t.push(a>>o&255);returnt}().reverse()}returnnull},t.IPv6=function(){functionr(r,t){varn,e,i,o,a,s;if(16===r.length)for(this.parts=[],n=e=0;e<=14;n=e+=2)this.parts.push(r[n]<<8|r[n+1]);else{if(8!==r.length)thrownewError("ipaddr: ipv6 part count should be 8 or 16");this.parts=r}for(i=0,o=(s=this.parts).length;i<o;i++)if(!(0<=(a=s[i])&&a<=65535))thrownewError("ipaddr: ipv6 part should fit in 16 bits");t&&(this.zoneId=t)}returnr.prototype.kind=function(){return"ipv6"},r.prototype.toString=function(){returnthis.toNormalizedString().replace(/((^|:)(0(:|$))+)/,"::")},r.prototype.toRFC5952String=function(){varr,t,n,e,i;for(e=/((^|:)(0(:|$)){2,})/g,i=this.toNormalizedString(),r=0,t=-1;n=e.exec(i);)n[0].length>t&&(r=n.index,t=n[0].length);returnt<0?i:i.substring(0,r)+"::"+i.substring(r+t)},r.prototype.toByteArray=function(){varr,t,n,e,i;for(r=[],t=0,n=(i=this.parts).length;t<n;t++)e=i[t],r.push(e>>8),r.push(255&e);returnr},r.prototype.toNormalizedString=function(){varr,t,n;returnr=function(){varr,n,e,i;for(i=[],r=0,n=(e=this.parts).length;r<n;r++)t=e[r],i.push(t.toString(16));returni}.call(this).join(":"),n="",this.zoneId&&(n="%"+this.zoneId),r+n},r.prototype.toFixedLengthString=function(){varr,t,n;returnr=function(){varr,n,e,i;for(i=[],r=0,n=(e=this.parts).length;r<n;r++)t=e[r],i.push(t.toString(16).padStart(4,"0"));returni}.call(this).join(":"),n="",this.zoneId&&(n="%"+this.zoneId),r+n},r.prototype.match=function(r,t){varn;if(void0===t&&(r=(n=r)[0],t=n[1]),"ipv6"!==r.kind())thrownewError("ipaddr: cannot match ipv6 address with non-ipv6 one");returna(this.parts,r.parts,16,t)},r.prototype.SpecialRanges={unspecified:[newr([0,0,0,0,0,0,0,0]),128],linkLocal:[newr([65152,0,0,0,0,0,0,0]),10],multicast:[newr([65280,0,0,0,0,0,0,0]),8],loopback:[newr([0,0,0,0,0,0,0,1]),128],uniqueLocal:[newr([64512,0,0,0,0,0,0,0]),7],ipv4Mapped:[newr([0,0,0,0,0,65535,0,0]),96],rfc6145:[newr([0,0,0,0,65535,0,0,0]),96],rfc6052:[newr([100,65435,0,0,0,0,0,0]),96],"6to4":[newr([8194,0,0,0,0,0,0,0]),16],teredo:[newr([8193,0,0,0,0,0,0,0]),32],reserved:[[newr([8193,3512,0,0,0,0,0,0]),32]]},r.prototype.range=function(){returnt.subnetMatch(this,this.SpecialRanges)},r.prototype.isIPv4MappedAddress=function(){return"ipv4Mapped"===this.range()},r.prototype.toIPv4Address=function(){varr,n,e;if(!this.isIPv4MappedAddress())thrownewError("ipaddr: trying to convert a generic ipv6 address to ipv4");returne=this.parts.slice(-2),r=e[0],n=e[1],newt.IPv4([r>>8,255&r,n>>8,255&n])},r.prototype.prefixLengthFromSubnetMask=function(){varr,t,n,e,i,o,a;for(a={0:16,32768:15,49152:14,57344:13,61440:12,63488:11,64512:10,65024:9,65280:8,65408:7,65472:6,65504:5,65520:4,65528:3,65532:2,65534:1,65535:0},r=0,i=!1,t=n=7;n>=0;t=n+=-1){if(!((e=this.parts[t])ina))returnnull;if(o=a[e],i&&0!==o)returnnull;16!==o&&(i=!0),r+=o}return128-r},r}(),i="(?:[0-9a-f]+::?)+",o={zoneIndex:newRegExp("%[0-9a-z]{1,}","i"),native:newRegExp("^(::)?("+i+")?([0-9a-f]+)?(::)?(%[0-9a-z]{1,})?$","i"),transitional:newRegExp("^((?:"+i+")|(?:::)(?:"+i+")?)"+n+"\\."+n+"\\."+n+"\\."+n+"(%[0-9a-z]{1,})?$","i")},r=function(r,t){varn,e,i,a,s,p;if(r.indexOf("::")!==r.lastIndexOf("::"))returnnull;for((p=(r.match(o.zoneIndex)||[])[0])&&(p=p.substring(1),r=r.replace(/%.+$/,"")),n=0,e=-1;(e=r.indexOf(":",e+1))>=0;)n++;if("::"===r.substr(0,2)&&n--,"::"===r.substr(-2,2)&&n--,n>t)returnnull;for(s=t-n,a=":";s--;)a+="0:";return":"===(r=r.replace("::",a))[0]&&(r=r.slice(1)),":"===r[r.length-1]&&(r=r.slice(0,-1)),t=function(){vart,n,e,o;for(o=[],t=0,n=(e=r.split(":")).length;t<n;t++)i=e[t],o.push(parseInt(i,16));returno}(),{parts:t,zoneId:p}},t.IPv6.parser=function(t){varn,e,i,a,s,p,u;if(o.native.test(t))returnr(t,8);if((a=t.match(o.transitional))&&(u=a[6]||"",(n=r(a[1].slice(0,-1)+u,6)).parts)){for(e=0,i=(p=[parseInt(a[2]),parseInt(a[3]),parseInt(a[4]),parseInt(a[5])]).length;e<i;e++)if(!(0<=(s=p[e])&&s<=255))returnnull;returnn.parts.push(p[0]<<8|p[1]),n.parts.push(p[2]<<8|p[3]),{parts:n.parts,zoneId:n.zoneId}}returnnull},t.IPv4.isIPv4=t.IPv6.isIPv6=function(r){returnnull!==this.parser(r)},t.IPv4.isValid=function(r){try{returnnewthis(this.parser(r)),!0}catch(r){returnr,!1}},t.IPv4.isValidFourPartDecimal=function(r){return!(!t.IPv4.isValid(r)||!r.match(/^(0|[1-9]\d*)(\.(0|[1-9]\d*)){3}$/))},t.IPv6.isValid=function(r){vart;if("string"==typeofr&&-1===r.indexOf(":"))return!1;try{returnt=this.parser(r),newthis(t.parts,t.zoneId),!0}catch(r){returnr,!1}},t.IPv4.parse=function(r){vart;if(null===(t=this.parser(r)))thrownewError("ipaddr: string is not formatted like ip address");returnnewthis(t)},t.IPv6.parse=function(r){vart;if(null===(t=this.parser(r)).parts)thrownewError("ipaddr: string is not formatted like ip address");returnnewthis(t.parts,t.zoneId)},t.IPv4.parseCIDR=function(r){vart,n,e;if((n=r.match(/^(.+)\/(\d+)$/))&&(t=parseInt(n[2]))>=0&&t<=32)returne=[this.parse(n[1]),t],Object.defineProperty(e,"toString",{value:function(){returnthis.join("/")}}),e;thrownewError("ipaddr: string is not formatted like an IPv4 CIDR range")},t.IPv4.subnetMaskFromPrefixLength=function(r){vart,n,e;if((r=parseInt(r))<0||r>32)thrownewError("ipaddr: invalid IPv4 prefix length");for(e=[0,0,0,0],n=0,t=Math.floor(r/8);n<t;)e[n]=255,n++;returnt<4&&(e[t]=Math.pow(2,r%8)-1<<8-r%8),newthis(e)},t.IPv4.broadcastAddressFromCIDR=function(r){vart,n,e,i,o;try{for(e=(t=this.parseCIDR(r))[0].toByteArray(),o=this.subnetMaskFromPrefixLength(t[1]).toByteArray(),i=[],n=0;n<4;)i.push(parseInt(e[n],10)|255^parseInt(o[n],10)),n++;returnnewthis(i)}catch(r){throwr,newError("ipaddr: the address does not have IPv4 CIDR format")}},t.IPv4.networkAddressFromCIDR=function(r){vart,n,e,i,o;try{for(e=(t=this.parseCIDR(r))[0].toByteArray(),o=this.subnetMaskFromPrefixLength(t[1]).toByteArray(),i=[],n=0;n<4;)i.push(parseInt(e[n],10)&parseInt(o[n],10)),n++;returnnewthis(i)}catch(r){throwr,newError("ipaddr: the address does not have IPv4 CIDR format")}},t.IPv6.parseCIDR=function(r){vart,n,e;if((n=r.match(/^(.+)\/(\d+)$/))&&(t=parseInt(n[2]))>=0&&t<=128)returne=[this.parse(n[1]),t],Object.defineProperty(e,"toString",{value:function(){returnthis.join("/")}}),e;thrownewError("ipaddr: string is not formatted like an IPv6 CIDR range")},t.isValid=function(r){returnt.IPv6.isValid(r)||t.IPv4.isValid(r)},t.parse=function(r){if(t.IPv6.isValid(r))returnt.IPv6.parse(r);if(t.IPv4.isValid(r))returnt.IPv4.parse(r);thrownewError("ipaddr: the address has neither IPv6 nor IPv4 format")},t.parseCIDR=function(r){try{returnt.IPv6.parseCIDR(r)}catch(n){n;try{returnt.IPv4.parseCIDR(r)}catch(r){throwr,newError("ipaddr: the address has neither IPv6 nor IPv4 CIDR format")}}},t.fromByteArray=function(r){varn;if(4===(n=r.length))returnnewt.IPv4(r);if(16===n)returnnewt.IPv6(r);thrownewError("ipaddr: the binary input is neither an IPv6 nor IPv4 address")},t.process=function(r){vart;returnt=this.parse(r),"ipv6"===t.kind()&&t.isIPv4MappedAddress()?t.toIPv4Address():t}}).call(this);