1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| var list = [ "162.158.0.0/15", "103.21.244.0/22", "173.245.48.0/20", "103.22.200.0/22", "103.31.4.0/22", "141.101.64.0/18", "108.162.192.0/18", "190.93.240.0/20", "188.114.96.0/20", "197.234.240.0/22", "198.41.128.0/17", "104.16.0.0/12", "172.64.0.0/13", "131.0.72.0/22" ]
let arr1 = [] for(let i = 0;i < list.length;i++){ arr1 = arr1.concat(init(list[i])) } console.log(arr1);
function init(ipmask){
let [ip,yanma] = ipmask.split('/') let yanmaArr = [] for(let i = 0;i < 32;i++){ yanmaArr.push(i < yanma ? "1" :"0") } yanmaArr.splice(24,0,',') yanmaArr.splice(16,0,',') yanmaArr.splice(8,0,',') let morenyanma = yanmaArr.join('').split(',')
ip = ip.split('.') ip.map((v,w)=>{ ip[w] = numToHex(v) }) let arr2 = [] for(let i = 0;i < ip.length;i ++){ arr2.push( parseInt(yu(ip[i],morenyanma[i]),2) ) } let output = [] for(let i = 0;i < Math.pow(2,32 - yanma) - 2;i++){ let arr = digui(arr2.concat(),3) output.push(arr) arr2 = arr }
return output } function digui(arr,n){ var arr = arr.concat() if(n < 1){ return arr; } arr[n] += 1 if(arr[n] >= 255){ arr = digui(arr,n-1) arr[n] = 0 } return arr; }
function yu(a='11111111',b='00000000'){ var arr1 = [] for(let i = 0 ;i < a.length;i++){ arr1.push((a[i] == b[i]) ? a[i] : 0) } return arr1.join('') } function numToHex(num){ let num1 = (num >>> 0).toString(2) let len = num1.length return len < 8 ? `${"0".repeat(8-len)}${num1}` : num1 }
|