ipmoyu.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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"]
  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. const {
  26. data: { data: countryList }
  27. } = await axios.get("http://global.ipmoyu.com/proxy/web/map/countryList", {
  28. params: {
  29. page: 1,
  30. limit: 1000
  31. }
  32. })
  33. const { data: template, config } = await axios.get(
  34. "http://192.168.50.47:25500/sub",
  35. {
  36. params: {
  37. target: "clash",
  38. url: "http://192.168.50.46:3000/download/collection/all?target=ClashMeta",
  39. insert: false,
  40. config: "https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_NoAuto.ini",
  41. emoji: true,
  42. list: false,
  43. xudp: false,
  44. udp: false,
  45. tfo: false,
  46. expand: true,
  47. scv: true,
  48. fdn: false,
  49. new_name: true
  50. }
  51. }
  52. )
  53. let countryId = countryList.find(i => i.abbr === country)?.id
  54. for (let bridge of bridges) {
  55. for (let net of nets) {
  56. const ips = net.subnets.flatMap(subnet => {
  57. return Array.from({ length: 200 }, (_, i) => `${subnet}.${i + 50}`)
  58. })
  59. const doc = parseDocument(template)
  60. doc.set("unified-delay", true)
  61. const proxies = doc.get("proxies")
  62. const proxyGroups = doc.get("proxy-groups")
  63. let rules = doc.get("rules").items
  64. proxies.add(doc.createNode(bridge, { flow: true }))
  65. let c = 0,
  66. g = 0
  67. ips.forEach((ip, i) => {
  68. if (i % groupSize === 0) {
  69. const groupProxies = Array.from(
  70. { length: proxyNumEachGroup },
  71. (_, j) => {
  72. const p = doc.createNode(
  73. {
  74. name: `${country}-${++c}`,
  75. type: "socks5",
  76. server: "global.ipmoyu.com",
  77. port: 3000,
  78. username: `haoge11_${countryId}_0_0_10_${randomstring.generate(
  79. { length: 8, charset: "alphanumeric" }
  80. )}_5_1`,
  81. password: "qaz112211",
  82. "dialer-proxy": bridge.name
  83. },
  84. { flow: true }
  85. )
  86. proxies.add(p)
  87. return p
  88. }
  89. )
  90. const group = doc.createNode(
  91. {
  92. name: `${country}-GROUP-${++g}`,
  93. type: "url-test",
  94. url: "http://www.gstatic.com/generate_204",
  95. interval: 150,
  96. tolerance: 50,
  97. proxies: groupProxies.map(p => p.get("name"))
  98. },
  99. { flow: true }
  100. )
  101. proxyGroups.add(group)
  102. }
  103. rules.unshift(
  104. `SRC-IP-CIDR,${ip}/32,${proxyGroups
  105. .get(proxyGroups.items.length - 1)
  106. .get("name")}`
  107. )
  108. })
  109. rules = commonRules
  110. .map(r => r.replace("$bridge", bridge.name))
  111. .concat(rules)
  112. doc.set("rules", rules)
  113. fs.writeFileSync(
  114. `dist/${net.router}-${country}-IPMOYU-${bridge.name}.yaml`,
  115. doc.toString({
  116. lineWidth: 0
  117. })
  118. )
  119. }
  120. }
  121. const doc = parseDocument(template)
  122. doc.set("unified-delay", true)
  123. const proxies = doc.get("proxies")
  124. proxies.add(doc.createNode(bridge, { flow: true }))
  125. countryList
  126. .filter(country => country.abbr && country.abbr !== "-")
  127. .sort((a, b) => a.abbr.localeCompare(b.abbr))
  128. .forEach((country, i) => {
  129. const p = doc.createNode(
  130. {
  131. name: `${country.abbr}-${country.chnName}`,
  132. type: "socks5",
  133. server: "global.ipmoyu.com",
  134. port: 3000,
  135. username: `haoge11_${country.id}_0_0_10_${randomstring.generate(
  136. {
  137. length: 8,
  138. charset: "alphanumeric"
  139. }
  140. )}_5_1`,
  141. password: "qaz112211",
  142. "dialer-proxy": bridge.name
  143. },
  144. { flow: true }
  145. )
  146. proxies.add(p)
  147. })
  148. fs.writeFileSync(`dist/IPMOYU-GLOBAL.yaml`, doc.toString({ lineWidth: 0 }))