• cloudfront
  • gcore
  • cloudflare

把子网掩码批量转换成ip地址

不同长度含ip个数

1
2
3
4
// 24 256 23 512 22 1024 21 2048 
// 20 4096 19 8192 18 16384 17 32768
// 16 65536 15 131072 14 262144 13 524288 12 1048576
// 11 2097152 10 4194304

cloudfront

IP 国家 地区
3.160.0.0/14 美国
3.164.0.0/18 美国
3.172.0.0/18 美国
13.32.0.0/15 德国 慕尼黑
13.35.0.0/16 美国 华盛顿
13.224.0.0/14 美国 华盛顿
13.249.0.0/16 法国 巴黎
15.158.0.0/16 美国 佐治亚
18.64.0.0/14 美国 马萨诸塞
18.68.0.0/16 美国 马萨诸塞
18.154.0.0/15 美国
18.160.0.0/15 美国
18.164.0.0/15 美国
18.172.0.0/15 美国 马萨诸塞
18.238.0.0/15 美国 马萨诸塞
18.244.0.0/15 美国 马萨诸塞
52.46.0.0/18 德国 柏林
52.84.0.0/15 美国 伊利诺伊
52.124.128.0/17 荷兰 阿姆斯
52.222.128.0/17 意大利 罗马
54.182.0.0/16 印度 马哈拉施特拉
54.192.0.0/16 英国 伦敦
54.230.0.0/17 英国 伦敦
54.230.128.0/18 荷兰 阿姆斯特丹
54.230.208.0/20 美国 伊利诺伊
54.230.200.0/21 德国 法兰克福
54.230.224.0/19 美国 佐治亚
54.239.128.0/18 美国 印第安纳
54.239.192.0/19 波兰 华沙
54.240.128.0/18 意大利 米兰
64.252.64.0/18 美国 弗吉尼亚
64.252.128.0/18 美国 佐治亚
65.8.0.0/16 印度 西孟加拉
65.9.0.0/17 美国 佛罗里达
65.9.128.0/18 美国 佛罗里达
70.132.0.0/18 美国 科罗拉多
71.152.0.0/17 美国 新泽西
99.84.0.0/16 英国 伦敦
99.86.0.0/16 美国 华盛顿
108.156.0.0/14 美国
108.138.0.0/15 美国
130.176.0.0/17 美国 加利福尼亚
130.176.128.0/18 美国 加利福尼亚
130.176.192.0/19 美国 加利福尼亚
130.176.224.0/20 美国 加利福尼亚
143.204.0.0/16 美国 华盛顿
144.220.0.0/16 美国 康涅狄格
204.246.168.0/22 美国 纽约
205.251.249.0/24 美国 纽约
205.251.250.0/23 美国 纽约
205.251.252.0/23 美国 印第安纳
204.246.164.0/22 新加坡
204.246.172.0/24 美国 华盛顿
204.246.173.0/24 美国 华盛顿
204.246.174.0/23 美国 佛罗里达
204.246.176.0/20 美国 加利福尼亚
205.251.200.0/21 美国 加利福尼亚
205.251.208.0/20 意大利 米兰
205.251.254.0/24 美国 印第安纳
216.137.32.0/19 美国 弗吉尼亚
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
const fs = require('fs')
let list = []
//cloudfront 以去除国区
//list = ["205.251.249.0/24","204.246.168.0/22","18.160.0.0/15","205.251.252.0/23","54.192.0.0/16","204.246.173.0/24","54.230.200.0/21","116.129.226.128/26","130.176.0.0/17","108.156.0.0/14","99.86.0.0/16","205.251.200.0/21","223.71.71.128/25","13.32.0.0/15","13.224.0.0/14","70.132.0.0/18","15.158.0.0/16","13.249.0.0/16","18.238.0.0/15","18.244.0.0/15","205.251.208.0/20","65.9.128.0/18","130.176.128.0/18","54.230.208.0/20","3.160.0.0/14","116.129.226.0/25","52.222.128.0/17","18.164.0.0/15","64.252.128.0/18","205.251.254.0/24","54.230.224.0/19","71.152.0.0/17","216.137.32.0/19","204.246.172.0/24","18.172.0.0/15","223.71.71.96/27","18.154.0.0/15","54.240.128.0/18","205.251.250.0/23","52.46.0.0/18","223.71.11.0/27","52.82.128.0/19","54.230.0.0/17","54.230.128.0/18","54.239.128.0/18","130.176.224.0/20","52.84.0.0/15","143.204.0.0/16","144.220.0.0/16","54.182.0.0/16","54.239.192.0/19","18.68.0.0/16","18.64.0.0/14","99.84.0.0/16","130.176.192.0/19","52.124.128.0/17","204.246.164.0/22","13.35.0.0/16","204.246.174.0/23","204.246.176.0/20","65.8.0.0/16","65.9.0.0/17","108.138.0.0/15","64.252.64.0/18","13.113.196.64/26","13.113.203.0/24","52.199.127.192/26","13.124.199.0/24","3.35.130.128/25","52.78.247.128/26","13.233.177.192/26","15.207.13.128/25","15.207.213.128/25","52.66.194.128/26","13.228.69.0/24","52.220.191.0/26","13.210.67.128/26","13.54.63.128/26","43.218.56.128/26","43.218.56.192/26","43.218.56.64/26","43.218.71.0/26","99.79.169.0/24","18.192.142.0/23","35.158.136.0/24","52.57.254.0/24","13.48.32.0/24","18.200.212.0/23","52.212.248.0/26","3.10.17.128/25","3.11.53.0/24","52.56.127.0/25","15.188.184.0/24","52.47.139.0/24","3.29.40.128/26","3.29.40.192/26","3.29.40.64/26","3.29.57.0/26","18.229.220.192/26","54.233.255.128/26","3.231.2.0/25","3.234.232.224/27","3.236.169.192/26","3.236.48.0/23","34.195.252.0/24","34.226.14.0/24","13.59.250.0/26","18.216.170.128/25","3.128.93.0/24","3.134.215.0/24","52.15.127.128/26","3.101.158.0/23","52.52.191.128/26","34.216.51.0/25","34.223.12.224/27","34.223.80.192/26","35.162.63.192/26","35.167.191.128/26","44.227.178.0/24","44.234.108.128/25","44.234.90.252/30"]
//gcore
//list = ["10.96.33.0/24", "217.21.47.160/28", "5.188.133.0/26", "82.114.163.144/30", "185.105.1.0/28", "45.82.100.0/26", "95.85.93.0/26", "92.46.108.104/30", "185.101.136.0/27", "81.253.239.12/30", "194.152.37.176/28", "80.15.252.0/31", "5.189.207.0/28", "93.123.11.0/26", "92.223.12.0/27", "82.148.98.40/29", "80.15.252.32/31", "5.188.132.0/28", "185.101.137.0/28", "5.101.222.0/28", "92.223.108.0/27", "89.218.28.16/28", "102.67.99.48/28", "80.93.210.0/26", "188.94.153.0/28", "181.39.11.208/30", "5.188.121.128/25", "87.120.106.0/26", "45.82.103.0/26", "81.253.239.4/30", "185.163.3.0/26", "103.211.151.20/31", "185.188.144.0/26", "134.0.219.24/30", "92.223.123.0/26", "92.223.116.192/26", "92.223.114.0/26", "92.223.63.0/27", "92.223.126.0/26", "5.1.106.248/30", "109.230.114.0/28", "78.111.103.0/26", "5.188.94.0/28", "80.15.252.8/31", "92.223.76.16/28", "181.174.80.180/30", "92.223.61.16/28", "5.101.217.0/28", "197.188.22.100/30", "80.240.113.0/26", "92.38.159.0/28", "212.188.76.64/28", "92.223.74.16/28", "185.158.211.184/29", "92.223.78.16/28", "102.68.141.72/30", "134.0.219.36/31", "80.15.252.16/31", "95.85.88.0/26", "62.209.27.232/31", "194.44.246.204/30", "92.223.122.160/27", "78.111.101.0/26", "92.223.112.0/26", "92.223.64.0/28", "82.97.205.0/26", "37.98.156.188/30", "79.133.108.0/26", "186.16.19.92/30", "45.65.8.0/26", "104.247.172.248/31", "92.38.159.0/26", "185.249.133.0/26", "178.160.192.36/30", "171.229.196.128/27", "180.149.90.64/30", "195.22.198.48/31", "195.34.58.18/31", "92.223.124.0/26", "185.239.153.0/24", "92.223.47.0/26", "91.243.83.0/26", "5.8.92.0/26", "92.223.43.0/26", "87.120.164.0/26", "190.95.248.32/30", "102.130.69.140/30", "5.188.7.0/26", "5.101.219.0/28", "80.93.221.0/26", "37.236.95.0/30", "213.156.151.0/26", "188.72.125.0/24", "93.123.38.0/26", "195.14.146.80/30", "167.160.20.172/31", "43.245.140.0/30", "92.223.120.0/24", "45.82.101.0/26", "92.223.118.0/27", "120.28.10.44/30", "81.253.239.8/30", "91.243.87.0/26", "213.156.144.0/26", "37.17.119.112/28", "95.85.69.0/26", "109.68.233.240/30", "95.85.92.0/26", "92.38.168.0/28", "197.225.145.24/30", "94.43.206.200/29", "150.107.126.0/26", "185.244.209.0/26", "82.213.5.48/30", "80.240.124.0/26", "92.223.110.0/27", "37.110.209.224/29", "46.19.99.4/30", "179.0.200.96/27", "5.101.68.0/27", "151.248.104.94/31", "1.37.77.96/28", "92.38.142.0/26", "195.34.58.16/31", "94.176.183.0/26", "81.253.239.32/30", "146.185.221.128/26", "81.253.239.0/30", "31.184.207.0/26", "170.238.234.216/30", "93.123.17.128/25", "171.234.242.192/27", "5.188.126.0/28", "92.223.122.128/25", "94.128.12.236/30", "197.215.140.232/29", "92.223.120.0/27", "217.76.64.88/30", "92.223.118.32/28", "81.253.239.28/30", "5.8.43.0/28", "92.223.68.16/28", "41.210.189.20/30", "160.242.112.240/30", "89.223.90.0/26", "92.223.107.32/27", "81.253.239.24/30", "92.38.170.0/28", "130.193.166.0/30", "197.148.108.104/29", "92.223.55.0/26", "5.252.26.0/26", "46.49.10.224/28", "92.223.92.16/28", "185.194.11.72/30"]
//cloudflare
list = ["173.245.48.0/20","103.21.244.0/22","141.101.64.0/18","108.162.192.0/18","190.93.240.0/20","188.114.96.0/20","198.41.128.0/17","162.158.0.0/15","104.16.0.0/13","104.24.0.0/14","172.64.0.0/13"]
let count = 0 //记总数
let arr1 = [] //保存全部数据的数组
list.map((v,i)=>{
arr1 = arr1.concat(init(list[i]))
})
let arr2 = []
for(v of arr1) {
arr2.push(v.join('.'))
}
// arr1.map(v=>{
// console.log(`"${v.join(".")}"`,",");
// //console.log(v);
// })
//console.log("共生成ip个数:",count);
//保存节点信息
fs.writeFile(`./ips.json`,JSON.stringify(arr2),function(){
console.log("执行完成");
})
function init(ipmask){
//console.log(ipmask);//运算之前的子掩码ip
//分割掩码ip
let [ip,yanma] = ipmask.split('/')
//console.log(ip,yanma);
let morenyanma = new Array()
for(let i = 0;i < 32;i++){
i < yanma ? morenyanma.push("1") : morenyanma.push("0")
}
morenyanma.splice(24,0,",")
morenyanma.splice(16,0,",")
morenyanma.splice(8,0,",")
morenyanma = morenyanma.join('').split(',')
ip = ip.split('.')
ip.map((v,w)=>{
ip[w] = numToHex(v)
})
// console.log(ip,morenyanma);
//求两个二进制数组的与运算
let arr2 = []
for(let i = 0;i < ip.length;i ++){
arr2.push( parseInt(yu(ip[i],morenyanma[i]),2) )
}
//console.log(arr2);//与运算后的ip地址
//console.log(Math.pow(2,32 - yanma));//网络号向主机号借几位, 可用主机号个数需要减2
let output = []
for(let i = 0;i < Math.pow(2,32 - yanma)-2;i++){
arr2 = arr2.concat()
digui(arr2,3)
output.push(arr2)
count ++;
console.log("count:",count,"ip:",arr2);
}
return output
}
//与运算
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){
//ip转换成2进制
let num1 = (num >>> 0).toString(2)
let len = num1.length
return len < 8 ? `${"0".repeat(8-len)}${num1}` : num1
}
//递归调用运算ip号段
function digui(ip,num){
if(num <= 1) return ip
ip[num] += 1
if(ip[num] >= 256){
ip[num] = 0
digui(ip,num - 1)
}
return ip
}