build-anti-bogus-domain.js 853 B

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