build-anti-bogus-domain.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. const { fetchWithRetry } = require('./lib/fetch-retry');
  2. const fs = require('fs');
  3. const path = require('path');
  4. const { isIP } = require('net');
  5. (async () => {
  6. console.time('Total Time - build-anti-bogus-domain');
  7. console.time('* Download bogus-nxdomain-list')
  8. const res = (await (await fetchWithRetry('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/bogus-nxdomain.china.conf')).text())
  9. .split('\n')
  10. .map(line => {
  11. if (line.startsWith('bogus-nxdomain=')) {
  12. return line.replace('bogus-nxdomain=', '');
  13. }
  14. return null
  15. })
  16. .filter(ip => typeof ip === 'string' && isIP(ip) !== 0);
  17. console.timeEnd('* Download bogus-nxdomain-list')
  18. const filePath = path.resolve(__dirname, '../Source/ip/reject.conf');
  19. const resultPath = path.resolve(__dirname, '../List/ip/reject.conf');
  20. const content = (await fs.promises.readFile(filePath, 'utf-8'))
  21. .replace(
  22. '# --- [Anti Bogus Domain Replace Me] ---',
  23. res.map(ip => `IP-CIDR,${ip}/32,no-resolve`).join('\n')
  24. );
  25. await fs.promises.writeFile(resultPath, content, 'utf-8');
  26. console.timeEnd('Total Time - build-anti-bogus-domain');
  27. })();