build-cidr.js 1012 B

12345678910111213141516171819202122232425262728
  1. const { default: got } = require('got-cjs');
  2. const { promises: fsPromises } = require('fs');
  3. const { resolve: pathResolve } = require('path');
  4. (async () => {
  5. const cidr = (await got('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt').text()).split('\n');
  6. const filteredCidr = cidr.filter(line => {
  7. if (line) {
  8. return !line.startsWith('#')
  9. }
  10. return false;
  11. })
  12. return fsPromises.writeFile(pathResolve(__dirname, '../List/ip/china_ip.conf'), makeCidrList(filteredCidr), { encoding: 'utf-8' });
  13. })();
  14. function makeCidrList(cidr) {
  15. const date = new Date();
  16. return `############################
  17. # Mainland China IPv4 CIDR
  18. # Data from vx.link (tmplink @ GitHub)
  19. # Last Updated: ${date.getFullYear()}-${date.getUTCMonth() + 1}-${date.getUTCDate()} ${date.getUTCHours()}:${date.getUTCMinutes()}:${date.getUTCSeconds()}
  20. # Routes: ${cidr.length}
  21. ############################\n` + cidr.map(i => `IP-CIDR,${i}`).join('\n') + '\n########### END ############\n';
  22. };