| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- // @ts-check
- const path = require('path');
- const { isIPv4, isIPv6 } = require('net');
- const { compareAndWriteFile } = require('./lib/string-array-compare');
- const { withBannerArray } = require('./lib/with-banner');
- const { fetchRemoteTextAndCreateReadlineInterface, readFileByLine } = require('./lib/fetch-remote-text-by-line');
- const { surgeRulesetToClashClassicalTextRuleset } = require('./lib/clash');
- (async () => {
- console.time('Total Time - build-anti-bogus-domain');
- console.time('* Download bogus-nxdomain-list');
- /** @type {string[]} */
- const res = [];
- for await (const line of await fetchRemoteTextAndCreateReadlineInterface('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/bogus-nxdomain.china.conf')) {
- if (line.startsWith('bogus-nxdomain=')) {
- res.push(line.replace('bogus-nxdomain=', ''));
- }
- }
- console.timeEnd('* Download bogus-nxdomain-list');
- const filePath = path.resolve(__dirname, '../Source/ip/reject.conf');
- /** @type {string[]} */
- const result = [];
- for await (const line of readFileByLine(filePath)) {
- if (line === '# --- [Anti Bogus Domain Replace Me] ---') {
- res.forEach(ip => {
- if (isIPv4(ip)) {
- result.push(`IP-CIDR,${ip}/32,no-resolve`);
- } else if (isIPv6(ip)) {
- result.push(`IP-CIDR6,${ip}/128,no-resolve`);
- }
- });
- } else {
- result.push(line);
- }
- }
- const description = [
- 'License: AGPL 3.0',
- 'Homepage: https://ruleset.skk.moe',
- 'GitHub: https://github.com/SukkaW/Surge',
- '',
- 'This file contains known addresses that are hijacking NXDOMAIN results returned by DNS servers.',
- '',
- 'Data from:',
- ' - https://github.com/felixonmars/dnsmasq-china-list'
- ];
- await Promise.all([
- compareAndWriteFile(
- withBannerArray(
- 'Sukka\'s Ruleset - Anti Bogus Domain',
- description,
- new Date(),
- result
- ),
- path.resolve(__dirname, '../List/ip/reject.conf')
- ),
- compareAndWriteFile(
- withBannerArray(
- 'Sukka\'s Ruleset - Anti Bogus Domain',
- description,
- new Date(),
- surgeRulesetToClashClassicalTextRuleset(result)
- ),
- path.resolve(__dirname, '../Clash/ip/reject.txt')
- )
- ]);
- console.timeEnd('Total Time - build-anti-bogus-domain');
- })();
|