mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-28 17:41:54 +08:00
Feat: auto generate anti-bogus-domain ip list
This commit is contained in:
26
Build/build-anti-bogus-domain.js
Normal file
26
Build/build-anti-bogus-domain.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const { fetch } = require('undici');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { isIP } = require('net');
|
||||
|
||||
(async () => {
|
||||
const res = (await (await fetch('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/bogus-nxdomain.china.conf')).text())
|
||||
.split('\n')
|
||||
.map(line => {
|
||||
if (line.startsWith('bogus-nxdomain=')) {
|
||||
return line.replace('bogus-nxdomain=', '');
|
||||
}
|
||||
|
||||
return null
|
||||
})
|
||||
.filter(ip => typeof ip === 'string' && isIP(ip) !== 0);
|
||||
|
||||
const filePath = path.resolve(__dirname, '../List/ip/reject.conf');
|
||||
const content = (await fs.promises.readFile(filePath, 'utf-8'))
|
||||
.replace(
|
||||
'# --- [Anti Bogus Domain Replace Me] ---',
|
||||
res.map(ip => `IP-CIDR,${ip}/32,no-resolve`).join('\n')
|
||||
);
|
||||
|
||||
await fs.promises.writeFile(filePath, content, 'utf-8');
|
||||
})();
|
||||
Reference in New Issue
Block a user