ipmoyu.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. let countryId = countryList.find(i => i.abbr === country)?.id
  66. for (let bridge of bridges) {
  67. for (let net of nets) {
  68. const ips = net.subnets.flatMap(subnet => {
  69. return Array.from({ length: 200 }, (_, i) => `${subnet}.${i + 50}`)
  70. })
  71. const doc = parseDocument(template)
  72. doc.set("unified-delay", true)
  73. const proxies = doc.get("proxies")
  74. const proxyGroups = doc.get("proxy-groups")
  75. let rules = doc.get("rules").items
  76. proxies.add(doc.createNode(bridge, { flow: true }))
  77. let c = 0,
  78. g = 0
  79. ips.forEach((ip, i) => {
  80. if (i % groupSize === 0) {
  81. const groupProxies = Array.from(
  82. { length: proxyNumEachGroup },
  83. (_, j) => {
  84. const p = doc.createNode(
  85. {
  86. name: `${country}-${++c}`,
  87. type: "socks5",
  88. server: "global.ipmoyu.com",
  89. port: 3000,
  90. username: `haoge11_${countryId}_0_0_10_${randomstring.generate(
  91. { length: 8, charset: "alphanumeric" }
  92. )}_5_1`,
  93. password: "qaz112211",
  94. "dialer-proxy": bridge.name,
  95. udp: true
  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 = commonRules
  123. .map(r => r.replace("$bridge", bridge.name))
  124. .concat(rules)
  125. doc.set("rules", rules)
  126. fs.writeFileSync(
  127. `dist/${net.router}-${country}-IPMOYU-${bridge.name}.yaml`,
  128. doc.toString({
  129. lineWidth: 0
  130. })
  131. )
  132. }
  133. }
  134. const doc = parseDocument(template)
  135. doc.set("unified-delay", true)
  136. const proxies = doc.get("proxies")
  137. proxies.add(doc.createNode(bridge, { flow: true }))
  138. countryList
  139. .filter(country => country.abbr && country.abbr !== "-")
  140. .sort((a, b) => a.abbr.localeCompare(b.abbr))
  141. .forEach((country, i) => {
  142. const p = doc.createNode(
  143. {
  144. name: `${country.abbr}-${country.chnName}`,
  145. type: "socks5",
  146. server: "global.ipmoyu.com",
  147. port: 3000,
  148. username: `haoge11_${country.id}_0_0_10_${randomstring.generate(
  149. {
  150. length: 8,
  151. charset: "alphanumeric"
  152. }
  153. )}_5_1`,
  154. password: "qaz112211",
  155. "dialer-proxy": bridge.name,
  156. udp: true
  157. },
  158. { flow: true }
  159. )
  160. proxies.add(p)
  161. })
  162. fs.writeFileSync(`dist/IPMOYU-GLOBAL.yaml`, doc.toString({ lineWidth: 0 }))