ipmoyu.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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://admin.uipoxy.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. const template = fs.readFileSync(`dist/sub.yaml`, "utf-8")
  67. let countryId = countryList.find(i => i.abbr === country)?.id
  68. for (let bridge of bridges) {
  69. for (let net of nets) {
  70. const ips = net.subnets.flatMap(subnet => {
  71. return Array.from({ length: 200 }, (_, i) => `${subnet}.${i + 50}`)
  72. })
  73. const doc = parseDocument(template)
  74. doc.set("dns", {
  75. nameserver: ["114.114.114.114", "223.5.5.5"],
  76. "proxy-server-nameserver": ["114.114.114.114"],
  77. "use-hosts": true,
  78. "default-nameserver": ["114.114.114.114", "223.5.5.5"]
  79. })
  80. doc.set("hosts", {
  81. "zipfile.mesgity.top": "154.21.92.47"
  82. })
  83. doc.set("unified-delay", true)
  84. const proxies = doc.get("proxies")
  85. const proxyGroups = doc.get("proxy-groups")
  86. let rules = doc.get("rules").items
  87. proxies.add(doc.createNode(bridge, { flow: true }))
  88. let c = 0,
  89. g = 0
  90. ips.forEach((ip, i) => {
  91. if (i % groupSize === 0) {
  92. const groupProxies = Array.from(
  93. { length: proxyNumEachGroup },
  94. (_, j) => {
  95. const p = doc.createNode(
  96. {
  97. name: `${country}-${++c}`,
  98. type: "socks5",
  99. server: "adv1.uipoxy.com",
  100. port: 3000,
  101. username: `haoge11-zone-custom-region-${country}-session-${randomstring.generate(
  102. {
  103. length: 8,
  104. charset: "alphanumeric"
  105. }
  106. )}-sessTime-300-rc-0`,
  107. password: "qaz112211",
  108. "dialer-proxy": bridge.name,
  109. udp: true
  110. },
  111. { flow: true }
  112. )
  113. proxies.add(p)
  114. return p
  115. }
  116. )
  117. const group = doc.createNode(
  118. {
  119. name: `${country}-GROUP-${++g}`,
  120. type: "url-test",
  121. url: "http://www.gstatic.com/generate_204",
  122. interval: 150,
  123. tolerance: 50,
  124. proxies: groupProxies.map(p => p.get("name"))
  125. },
  126. { flow: true }
  127. )
  128. proxyGroups.add(group)
  129. }
  130. rules.unshift(
  131. `SRC-IP-CIDR,${ip}/32,${proxyGroups
  132. .get(proxyGroups.items.length - 1)
  133. .get("name")}`
  134. )
  135. })
  136. rules = commonRules
  137. .map(r => r.replace("$bridge", bridge.name))
  138. .concat(rules)
  139. doc.set("rules", rules)
  140. fs.writeFileSync(
  141. `dist/${net.router}-${country}-IPMOYU-${bridge.name}.yaml`,
  142. doc.toString({
  143. lineWidth: 0
  144. })
  145. )
  146. }
  147. }
  148. const doc = parseDocument(template)
  149. doc.set("unified-delay", true)
  150. const proxies = doc.get("proxies")
  151. proxies.add(doc.createNode(bridge, { flow: true }))
  152. countryList
  153. .filter(country => country.abbr && country.abbr !== "-")
  154. .sort((a, b) => a.abbr.localeCompare(b.abbr))
  155. .forEach((country, i) => {
  156. const p = doc.createNode(
  157. {
  158. name: `${country.abbr}-${country.chnName}`,
  159. type: "socks5",
  160. server: "adv1.uipoxy.com",
  161. port: 3000,
  162. username: `haoge11-zone-custom-region-${country.abbr}-session-${randomstring.generate(
  163. {
  164. length: 8,
  165. charset: "alphanumeric"
  166. }
  167. )}-sessTime-300-rc-0`,
  168. password: "qaz112211",
  169. "dialer-proxy": bridge.name,
  170. udp: true
  171. },
  172. { flow: true }
  173. )
  174. proxies.add(p)
  175. })
  176. fs.writeFileSync(`dist/IPMOYU-GLOBAL.yaml`, doc.toString({ lineWidth: 0 }))