1 line
13 KiB
JavaScript
1 line
13 KiB
JavaScript
|
|
(()=>{var t={104:function(t){(function(e){"use strict";const r="(0?\\d+|0x[a-f0-9]+)";const n={fourOctet:new RegExp(`^${r}\\.${r}\\.${r}\\.${r}$`,"i"),threeOctet:new RegExp(`^${r}\\.${r}\\.${r}$`,"i"),twoOctet:new RegExp(`^${r}\\.${r}$`,"i"),longValue:new RegExp(`^${r}$`,"i")};const i=new RegExp(`^0[0-7]+$`,"i");const s=new RegExp(`^0x[a-f0-9]+$`,"i");const o="%[0-9a-z]{1,}";const a="(?:[0-9a-f]+::?)+";const p={zoneIndex:new RegExp(o,"i"),native:new RegExp(`^(::)?(${a})?([0-9a-f]+)?(::)?(${o})?$`,"i"),deprecatedTransitional:new RegExp(`^(?:::)(${r}\\.${r}\\.${r}\\.${r}(${o})?)$`,"i"),transitional:new RegExp(`^((?:${a})|(?:::)(?:${a})?)${r}\\.${r}\\.${r}\\.${r}(${o})?$`,"i")};function expandIPv6(t,e){if(t.indexOf("::")!==t.lastIndexOf("::")){return null}let r=0;let n=-1;let i=(t.match(p.zoneIndex)||[])[0];let s,o;if(i){i=i.substring(1);t=t.replace(/%.+$/,"")}while((n=t.indexOf(":",n+1))>=0){r++}if(t.substr(0,2)==="::"){r--}if(t.substr(-2,2)==="::"){r--}if(r>e){return null}o=e-r;s=":";while(o--){s+="0:"}t=t.replace("::",s);if(t[0]===":"){t=t.slice(1)}if(t[t.length-1]===":"){t=t.slice(0,-1)}e=function(){const e=t.split(":");const r=[];for(let t=0;t<e.length;t++){r.push(parseInt(e[t],16))}return r}();return{parts:e,zoneId:i}}function matchCIDR(t,e,r,n){if(t.length!==e.length){throw new Error("ipaddr: cannot match CIDR for objects with different lengths")}let i=0;let s;while(n>0){s=r-n;if(s<0){s=0}if(t[i]>>s!==e[i]>>s){return false}n-=r;i+=1}return true}function parseIntAuto(t){if(s.test(t)){return parseInt(t,16)}if(t[0]==="0"&&!isNaN(parseInt(t[1],10))){if(i.test(t)){return parseInt(t,8)}throw new Error(`ipaddr: cannot parse ${t} as octal`)}return parseInt(t,10)}function padPart(t,e){while(t.length<e){t=`0${t}`}return t}const u={};u.IPv4=function(){function IPv4(t){if(t.length!==4){throw new Error("ipaddr: ipv4 octet count should be 4")}let e,r;for(e=0;e<t.length;e++){r=t[e];if(!(0<=r&&r<=255)){throw new Error("ipaddr: ipv4 octet should fit in 8 bits")}}this.octets=t}IPv4.prototype.SpecialRanges={unspecified:[[new IPv4([0,0,0,0]),8]],broadcast:[[new IPv4([255,255,255,255]),32]],multicast:[[new IPv4([224,0,0,0]),4]],linkLocal:[[new IPv4([169,254,0,0]),16]],loopback:[[new IPv4([127,0,0,0]),8]],carrierGradeNat:[[new IPv4([100,64,0,0]),10]],private:[[new IPv4([10,0,0,0]),8],[new IPv4([172,16,0,0]),12],[new IPv4([192,168,0,0]),16]],reserved:[[new IPv4([192,0,0,0]),24],[new IPv4([192,0,2,0]),24],[new IPv4([192,88,99,0]),24],[new IPv4([198,18,0,0]),15],[new IPv4([198,51,100,0]),24],[new IPv4([203,0,113,0]),24],[new IPv4([240,0,0,0]),4]],as112:[[new IPv4([192,175,48,0]),24],[new IPv4([192,31,196,0]),24]],amt:[[new IPv4([192,52,193,0]),24]]};IPv4.prototype.kind=function(){return"ipv4"};IPv4.prototype.match=function(t,e){let r;if(e===undefined){r=t;t=r[0];e=r[1]}if(t.kind()!=="ipv4"){throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one")}return matchCIDR(this.octets,t.octets,8,e)};IPv4.prototype.prefixLengthFromSubnetMask=function(){let t=0;let e=false;const r={0:8,128:7,192:6,224:5,240:4,248:3,252:2,254:1,255:0};let n,i,s;for(n=3;n>=0;n-=1){i=this.octets[n];if(i in r){s=r[i];if(e&&s!==0){return null}if(s!==8){e=true}t+=s}else{return null}}return 32-t};IPv4.prototype.range=function(){return u.subnetMatch(this,this.SpecialRanges)};IPv4.prototype.toByteArray=function(){return this.octets.slice(0)};IPv4.prototype.toIPv4MappedAddress=function(){return u.IPv6.parse(`::ffff:${this.toString()}`)};IPv4.prototype.toNormalizedString=function(){return this.toString()};IPv4.prototype.toString=function(){return this.octets.join(".")};return IPv4}();u.IPv4.broadcastAddressFromCIDR=function(t){try{const e=this.parseCIDR(t);const r=e[0].toByteArray();const n=this.subnetMaskFromPrefixLength(e[1]).toByteArray();const i=[];let s=0;while(s<4){i.push(parseInt(r[s],10)|parseInt(n[s],10)^255);s++}return new this(i)}catch(t){throw new Error("ipaddr: the address does not have IPv4 CIDR format")}};u.IPv4.isIPv4=function(t){return this.parser(t)!==null};u.IPv4.isValid=function(t){try{new this(this.parser(t));return true}catch(t){return false}};
|