(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&&(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(eint)for(i=t[e],!i[0]||i[0]instanceofArray||(i=[i]),a=0,s=i.length;s>a;a++)if(o=i[a],r.match.apply(r,o))returne;returnn},t.IPv4=function(){functionr(r){vart,n,e;if(4!==r.length)thrownewError("ipaddr: ipv4 octet count should be 4");for(n=0,e=r.length;e>n;n++)if(t=r[n],!(t>=0&&255>=t))thrownewError("ipaddr: ipv4 octet is a byte");this.octets=r}returnr.prototype.kind=function(){return"ipv4"},r.prototype.toString=function(){returnthis.octets.join(".")},r.prototype.toByteArray=function(){returnthis.octets.slice(0)},r.prototype.match=function(r,t){varn;if(void0===t&&(n=r,r=n[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]],"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}(),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(o=t.slice(1,6),a=[],r=0,e=o.length;e>r;r++)i=o[r],a.push(n(i));returna}();if(t=r.match(e.longValue)){if(a=n(t[1]),a>4294967295||0>a)thrownewError("ipaddr: address outside defined range");returnfunction(){varr,t;for(t=[],o=r=0;24>=r;o=r+=8)t.push(a>>o&255);returnt}().reverse()}returnnull},t.IPv6=function(){functionr(r){vart,n,e;if(8!==r.length)thrownewError("ipaddr: ipv6 part count should be 8");for(n=0,e=r.length;e>n;n++)if(t=r[n],!(t>=0&&65535>=t))thrownewError("ipaddr: ipv6 part should fit to two octets");this.parts=r}returnr.prototype.kind=function(){return"ipv6"},r.prototype.toString=function(){varr,t,n,e,i,o,a;for(i=function(){varr,n,e,i;for(e=this.parts,i=[],r=0,n=e.length;n>r;r++)t=e[r],i.push(t.toString(16));returni}.call(this),r=[],n=function(t){returnr.push(t)},e=0,o=0,a=i.length;a>o;o++)switch(t=i[o],e){case0:n("0"===t?"":t),e=1;break;case1:"0"===t?e=2:n(t);break;case2:"0"!==t&&(n(""),n(t),e=3);break;case3:n(t)}return2===e&&(n(""),n("")),r.join(":")},r.prototype.toByteArray=function(){varr,t,n,e,i;for(r=[],i=this.parts,n=0,e=i.length;e>n;n++)t=i[n],r.push(t>>8),r.push(255&t);returnr},r.prototype.toNormalizedString=function(){varr;returnfunction(){vart,n,e,i;for(e=this.parts,i=[],t=0,n=e.length;n>t;t++)r=e[t],i.push(r.toString(16));returni}.call(this).join(":")},r.prototype.match=function(r,t){varn;if(void0===t&&(n=r,r=n[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}(),i="(?:[0-9a-f]+::?)+",o={"native":newRegExp("^(::)?("+i+")?([0-9a-f]+)?(::)?$","i"),transitional:newRegExp("^((?:"+i+")|(?:::)(?:"+i+")?)"+(""+n+"\\."+n+"\\."+n+"\\."+n+"$"),"i")},r=function(r,t){varn,e,i,o,a;if(r.indexOf("::")!==r.lastIndexOf("::"))returnnull;for(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(a=t-n,o=":";a--;)o+="0:";returnr=r.replace("::",o),":"===r[0]&&(r=r.slice(1)),":"===r[r.length-1]&&(r=r.slice(0,-1)),function(){vart,n,e,o;for(e=r.split(":"),o=[],t=0,n=e.length;n>t;t++)i=e[t],o.push(parseInt(i,16));returno}()},t.IPv6.parser=function(t){varn,e;returnt.match(o["native"])?r(t,8):(n=t.match(o.transitional))&&(e=r(n[1].slice(0,-1),6))?(e.push(parseInt(n[2])<<8|parseInt(n[3])),e.push(parseInt(n[4])<<8|parseInt(n[5])),e):null},t.IPv4.isIPv4=t.IPv6.isIPv6=function(r){returnnull!==this.parser(r)},t.IPv4.isValid=function(r){vart;try{returnnewthis(this.parser(r)),!0}catch(n){returnt=n,!1}},t.IPv6.isValid=function(r){vart;if("string"==typeofr&&-1===r.indexOf(":"))return!1;try{returnnewthis(this.parser(r)),!0}catch(n){returnt=n,!1}},t.IPv4.parse=t.IPv6.parse=function(r){vart;if(t=this.parser(r),null===t)thrownewError("ipaddr: string is not formatted like ip address");returnnewthis(t)},t.IPv4.parseCIDR=function(r){vart,n;if((n=r.match(/^(.+)\/(\d+)$/))&&(t=parseInt(n[2]),t>=0&&32>=t))return[this.parse(n[1]),t];thrownewError("ipaddr: string is not formatted like an IPv4 CIDR range")},t.IPv6.parseCIDR=function(r){vart,n;if((n=r.match(/^(.+)\/(\d+)$/))&&(t=parseInt(n[2]),t>=0&&128>=t))return[this.parse(n[1]),t];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){varn;try{returnt.IPv6.parseCIDR(r)}catch(e){n=e;try{returnt.IPv4.parseCIDR(r)}catch(e){thrown=e,newError("ipaddr: the address has neither IPv6 nor IPv4 CIDR format")}}},t.process=function(r){vart;returnt=this.parse(r),"ipv6"===t.kind()&&t.isIPv4MappedAddress()?t.toIPv4Address():t}}).call(this);