-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
42 lines (33 loc) · 1.15 KB
/
index.js
File metadata and controls
42 lines (33 loc) · 1.15 KB
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
import { get } from 'node:https';
import { writeFile, mkdir } from 'node:fs/promises';
const urls = [
'https://www.cloudflare.com/ips-v4',
'https://www.cloudflare.com/ips-v6',
];
const download = url => new Promise((resolve, reject) => {
console.log('GET', url);
get(url, res => {
if (res.statusCode !== 200) {
res.resume();
return reject(new Error(`Request failed: ${res.statusCode}`));
}
const chunks = [];
res.on('data', chunk => chunks.push(chunk));
res.on('end', () => resolve(Buffer.concat(chunks).toString('utf8').trim()));
}).on('error', reject);
});
const main = async () => {
await mkdir('lists', { recursive: true });
const contents = await Promise.all(urls.map(download));
const ips = contents.join('\n').trim().split('\n').filter(Boolean);
// Raw
await writeFile('lists/cloudflare_ips_raw.txt', ips.join('\n') + '\n');
console.log('✅ Updated lists/cloudflare_ips_raw.txt');
// Nginx
await writeFile('lists/cloudflare_ips_nginx.conf', ips.map(ip => `set_real_ip_from ${ip};`).join('\n') + '\n');
console.log('✅ Updated lists/cloudflare_ips_nginx.conf');
};
main().catch(err => {
console.error(err);
process.exit(1);
});