ipmoyu1.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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: "10.2.100.1",
  14. subnets: ["10.2.100"]
  15. },
  16. {
  17. router: "10.2.101.1",
  18. subnets: ["10.2.101"]
  19. },
  20. {
  21. router: "10.2.102.1",
  22. subnets: ["10.2.102"]
  23. }
  24. ]
  25. const {
  26. data: { data: countryList }
  27. } = await axios.get("http://admin.uipoxy.com/proxy/web/map/countryList", {
  28. params: {
  29. page: 1,
  30. limit: 1000
  31. }
  32. })
  33. const template = fs.readFileSync(`dist/sub-vn.yaml`, "utf-8")
  34. let countryId = countryList.find(i => i.abbr === country)?.id
  35. for (let bridge of bridges) {
  36. for (let net of nets) {
  37. const ips = net.subnets.flatMap(subnet => {
  38. return Array.from({ length: 200 }, (_, i) => `${subnet}.${i + 50}`)
  39. })
  40. const doc = parseDocument(template)
  41. doc.set("dns", {
  42. nameserver: ["8.8.8.8", "114.114.114.114"],
  43. "proxy-server-nameserver": ["8.8.8.8"],
  44. "use-hosts": true,
  45. "default-nameserver": ["8.8.8.8", "114.114.114.114"]
  46. })
  47. doc.set("hosts", {
  48. "zipfile.mesgity.top": "154.21.92.47"
  49. })
  50. doc.set("unified-delay", true)
  51. const proxies = doc.get("proxies")
  52. const proxyGroups = []
  53. doc.set("proxy-groups", proxyGroups)
  54. let rules = doc.get("rules").items
  55. proxies.add(doc.createNode(bridge, { flow: true }))
  56. let c = 0,
  57. g = 0
  58. ips.forEach((ip, i) => {
  59. if (i % groupSize === 0) {
  60. const groupProxies = Array.from(
  61. { length: proxyNumEachGroup },
  62. (_, j) => {
  63. const p = doc.createNode(
  64. {
  65. name: `${country}-${++c}`,
  66. type: "socks5",
  67. server: "adv1.uipoxy.com",
  68. port: 3000,
  69. username: `haoge11_${countryId}_0_0_10_${randomstring.generate({
  70. length: 8,
  71. charset: "alphanumeric"
  72. })}_5_1`,
  73. password: "qaz112211",
  74. "dialer-proxy": bridge.name,
  75. udp: true
  76. },
  77. { flow: true }
  78. )
  79. proxies.add(p)
  80. return p
  81. }
  82. )
  83. const group = doc.createNode(
  84. {
  85. name: `${country}-GROUP-${++g}`,
  86. type: "url-test",
  87. url: "http://www.gstatic.com/generate_204",
  88. interval: 150,
  89. tolerance: 50,
  90. proxies: groupProxies.map(p => p.get("name"))
  91. },
  92. { flow: true }
  93. )
  94. proxyGroups.push(group)
  95. }
  96. rules.unshift(
  97. `SRC-IP-CIDR,${ip}/32,${proxyGroups[proxyGroups.length - 1].get("name")}`
  98. )
  99. })
  100. rules = commonRules
  101. .map(r => r.replace("$bridge", bridge.name))
  102. .concat(rules)
  103. doc.set("rules", rules)
  104. fs.writeFileSync(
  105. `dist/${net.router}-${country}-IPMOYU-${bridge.name}.yaml`,
  106. doc.toString({
  107. lineWidth: 0
  108. })
  109. )
  110. }
  111. }
  112. const doc = parseDocument(template)
  113. doc.set("unified-delay", true)
  114. const proxies = doc.get("proxies")
  115. proxies.add(doc.createNode(bridge, { flow: true }))
  116. countryList
  117. .filter(country => country.abbr && country.abbr !== "-")
  118. .sort((a, b) => a.abbr.localeCompare(b.abbr))
  119. .forEach((country, i) => {
  120. const p = doc.createNode(
  121. {
  122. name: `${country.abbr}-${country.chnName}`,
  123. type: "socks5",
  124. server: "adv1.uipoxy.com",
  125. port: 3000,
  126. username: `haoge11_${country.id}_0_0_10_${randomstring.generate({
  127. length: 8,
  128. charset: "alphanumeric"
  129. })}_5_1`,
  130. password: "qaz112211",
  131. udp: true
  132. },
  133. { flow: true }
  134. )
  135. proxies.add(p)
  136. })
  137. fs.writeFileSync(`dist/IPMOYU-GLOBAL.yaml`, doc.toString({ lineWidth: 0 }))