ipmoyu.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import { Document, parseDocument } from "yaml"
  2. import fs from "fs"
  3. import axios from "axios"
  4. import * as randomstring from "randomstring"
  5. import { bridges } from "./bridges.js"
  6. import { commonRules } from "./rules.js"
  7. const country = "US"
  8. const groupSize = 1
  9. const proxyNumEachGroup = 2
  10. const bridge = bridges[0]
  11. const nets = [
  12. {
  13. router: "192.168.6.1",
  14. subnets: ["192.168.10", "10.1.100", "10.1.101", "10.1.102"]
  15. },
  16. {
  17. router: "192.168.7.1",
  18. subnets: ["192.168.11", "192.168.12"]
  19. },
  20. {
  21. router: "192.168.8.1",
  22. subnets: ["192.168.13", "192.168.14"]
  23. },
  24. {
  25. router: "192.168.9.1",
  26. subnets: ["192.168.9"]
  27. },
  28. {
  29. router: "10.1.103.1",
  30. subnets: ["10.1.103"]
  31. },
  32. {
  33. router: "10.1.104.1",
  34. subnets: ["10.1.104"]
  35. }
  36. ]
  37. const {
  38. data: { data: countryList }
  39. } = await axios.get("http://global.ipmoyu.com/proxy/web/map/countryList", {
  40. params: {
  41. page: 1,
  42. limit: 1000
  43. }
  44. })
  45. const { data: template, config } = await axios.get(
  46. "http://192.168.50.47:25500/sub",
  47. {
  48. params: {
  49. target: "clash",
  50. url: "http://192.168.50.46:3000/download/collection/all?target=ClashMeta",
  51. insert: false,
  52. config: "https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_NoAuto.ini",
  53. emoji: true,
  54. list: false,
  55. xudp: true,
  56. udp: true,
  57. tfo: false,
  58. expand: true,
  59. scv: true,
  60. fdn: false,
  61. new_name: true
  62. }
  63. }
  64. )
  65. fs.writeFileSync(`dist/sub.yaml`, template)
  66. let countryId = countryList.find(i => i.abbr === country)?.id
  67. for (let bridge of bridges) {
  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("dns", {
  74. nameserver: ["114.114.114.114", "223.5.5.5"],
  75. "proxy-server-nameserver": ["114.114.114.114"],
  76. "use-hosts": true,
  77. "default-nameserver": ["114.114.114.114", "223.5.5.5"]
  78. })
  79. doc.set("hosts", {
  80. "zipfile.mesgity.top": "154.21.92.47"
  81. })
  82. doc.set("unified-delay", true)
  83. const proxies = doc.get("proxies")
  84. const proxyGroups = doc.get("proxy-groups")
  85. let rules = doc.get("rules").items
  86. proxies.add(doc.createNode(bridge, { flow: true }))
  87. let c = 0,
  88. g = 0
  89. ips.forEach((ip, i) => {
  90. if (i % groupSize === 0) {
  91. const groupProxies = Array.from(
  92. { length: proxyNumEachGroup },
  93. (_, j) => {
  94. const p = doc.createNode(
  95. {
  96. name: `${country}-${++c}`,
  97. type: "socks5",
  98. server: "global.ipmoyu.com",
  99. port: 3000,
  100. username: `haoge11_${countryId}_0_0_10_${randomstring.generate(
  101. {
  102. length: 8,
  103. charset: "alphanumeric"
  104. }
  105. )}_5_1`,
  106. password: "qaz112211",
  107. "dialer-proxy": bridge.name,
  108. udp: true
  109. },
  110. { flow: true }
  111. )
  112. proxies.add(p)
  113. return p
  114. }
  115. )
  116. const group = doc.createNode(
  117. {
  118. name: `${country}-GROUP-${++g}`,
  119. type: "url-test",
  120. url: "http://www.gstatic.com/generate_204",
  121. interval: 150,
  122. tolerance: 50,
  123. proxies: groupProxies.map(p => p.get("name"))
  124. },
  125. { flow: true }
  126. )
  127. proxyGroups.add(group)
  128. }
  129. rules.unshift(
  130. `SRC-IP-CIDR,${ip}/32,${proxyGroups
  131. .get(proxyGroups.items.length - 1)
  132. .get("name")}`
  133. )
  134. })
  135. rules = commonRules
  136. .map(r => r.replace("$bridge", bridge.name))
  137. .concat(rules)
  138. doc.set("rules", rules)
  139. fs.writeFileSync(
  140. `dist/${net.router}-${country}-IPMOYU-${bridge.name}.yaml`,
  141. doc.toString({
  142. lineWidth: 0
  143. })
  144. )
  145. }
  146. }
  147. const doc = parseDocument(template)
  148. doc.set("unified-delay", true)
  149. const proxies = doc.get("proxies")
  150. proxies.add(doc.createNode(bridge, { flow: true }))
  151. countryList
  152. .filter(country => country.abbr && country.abbr !== "-")
  153. .sort((a, b) => a.abbr.localeCompare(b.abbr))
  154. .forEach((country, i) => {
  155. const p = doc.createNode(
  156. {
  157. name: `${country.abbr}-${country.chnName}`,
  158. type: "socks5",
  159. server: "global.ipmoyu.com",
  160. port: 3000,
  161. username: `haoge11_${country.id}_0_0_10_${randomstring.generate(
  162. {
  163. length: 8,
  164. charset: "alphanumeric"
  165. }
  166. )}_5_1`,
  167. password: "qaz112211",
  168. "dialer-proxy": bridge.name,
  169. udp: true
  170. },
  171. { flow: true }
  172. )
  173. proxies.add(p)
  174. })
  175. fs.writeFileSync(`dist/IPMOYU-GLOBAL.yaml`, doc.toString({ lineWidth: 0 }))