index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { Document, parseDocument } from "yaml"
  2. import fs from "fs"
  3. import axios from "axios"
  4. import * as randomstring from "randomstring"
  5. const country = "US"
  6. const groupSize = 1
  7. const proxyNumEachGroup = 2
  8. const bridge = {
  9. name: "bridge",
  10. server: "laboratory.mesgity.top",
  11. port: 15166,
  12. "reality-opts": {
  13. "public-key": "NWDoTczcSP-hxIhhFQt8J_m9jCG554igEaOFr81ISyQ",
  14. "short-id": "340026c5e60e"
  15. },
  16. "client-fingerprint": "chrome",
  17. type: "vless",
  18. uuid: "bde0c64d-1f42-46ef-a207-3d0adee29ee8",
  19. tls: true,
  20. tfo: false,
  21. "skip-cert-verify": false,
  22. servername: "yahoo.com",
  23. network: "tcp"
  24. }
  25. const nets = [
  26. {
  27. router: "192.168.6.1",
  28. subnets: ["192.168.10"]
  29. },
  30. {
  31. router: "192.168.7.1",
  32. subnets: ["192.168.11", "192.168.12"]
  33. },
  34. {
  35. router: "192.168.8.1",
  36. subnets: ["192.168.13", "192.168.14"]
  37. }
  38. ]
  39. const {
  40. data: { data: countryList }
  41. } = await axios.get("http://global.ipmoyu.com/proxy/web/map/countryList", {
  42. params: {
  43. page: 1,
  44. limit: 1000
  45. }
  46. })
  47. const { data: template, config } = await axios.get(
  48. "http://192.168.50.47:25500/sub",
  49. {
  50. params: {
  51. target: "clash",
  52. url: "http://192.168.50.46:3000/download/collection/all?target=ClashMeta",
  53. insert: false,
  54. config: "https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_NoAuto.ini",
  55. emoji: true,
  56. list: false,
  57. xudp: false,
  58. udp: false,
  59. tfo: false,
  60. expand: true,
  61. scv: true,
  62. fdn: false,
  63. new_name: true
  64. }
  65. }
  66. )
  67. let countryId = countryList.find(i => i.abbr === country)?.id
  68. for (let net of nets) {
  69. const ips = net.subnets.flatMap(subnet => {
  70. return Array.from({ length: 200 }, (_, i) => `${subnet}.${i + 50}`)
  71. })
  72. const doc = parseDocument(template)
  73. doc.set("unified-delay", true)
  74. const proxies = doc.get("proxies")
  75. const proxyGroups = doc.get("proxy-groups")
  76. let rules = doc.get("rules").items
  77. proxies.add(doc.createNode(bridge, { flow: true }))
  78. let c = 0,
  79. g = 0
  80. ips.forEach((ip, i) => {
  81. if (i % groupSize === 0) {
  82. const groupProxies = Array.from(
  83. { length: proxyNumEachGroup },
  84. (_, j) => {
  85. const p = doc.createNode(
  86. {
  87. name: `${country}-${++c}`,
  88. type: "socks5",
  89. server: "global.ipmoyu.com",
  90. port: 3000,
  91. username: `splashy6_${countryId}_0_0_10_${randomstring.generate(
  92. { length: 8, charset: "alphanumeric" }
  93. )}_5_1`,
  94. password: "Lhw8MFcTdj",
  95. "dialer-proxy": "bridge"
  96. },
  97. { flow: true }
  98. )
  99. proxies.add(p)
  100. return p
  101. }
  102. )
  103. const group = doc.createNode(
  104. {
  105. name: `${country}-GROUP-${++g}`,
  106. type: "url-test",
  107. url: "http://www.gstatic.com/generate_204",
  108. interval: 150,
  109. tolerance: 50,
  110. proxies: groupProxies.map(p => p.get("name"))
  111. },
  112. { flow: true }
  113. )
  114. proxyGroups.add(group)
  115. }
  116. rules.unshift(
  117. `SRC-IP-CIDR,${ip}/32,${proxyGroups
  118. .get(proxyGroups.items.length - 1)
  119. .get("name")}`
  120. )
  121. })
  122. rules = [
  123. "DOMAIN-SUFFIX,izouma.com,DIRECT",
  124. "IP-CIDR,47.98.225.28/32,DIRECT",
  125. "IP-CIDR,8.149.128.251/32,DIRECT",
  126. "DOMAIN-SUFFIX,baidu.com,DIRECT",
  127. "DOMAIN-SUFFIX,aliyuncs.com,DIRECT"
  128. ].concat(rules)
  129. doc.set("rules", rules)
  130. fs.writeFileSync(
  131. `dist/${country}-IPMOYU-${net.router}.yaml`,
  132. doc.toString({
  133. lineWidth: 0
  134. })
  135. )
  136. }