ipmoyu1.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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://adv1.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. udp: true
  75. },
  76. { flow: true }
  77. )
  78. proxies.add(p)
  79. return p
  80. }
  81. )
  82. const group = doc.createNode(
  83. {
  84. name: `${country}-GROUP-${++g}`,
  85. type: "url-test",
  86. url: "http://www.gstatic.com/generate_204",
  87. interval: 150,
  88. tolerance: 50,
  89. proxies: groupProxies.map(p => p.get("name"))
  90. },
  91. { flow: true }
  92. )
  93. proxyGroups.push(group)
  94. }
  95. rules.unshift(
  96. `SRC-IP-CIDR,${ip}/32,${proxyGroups[proxyGroups.length - 1].get("name")}`
  97. )
  98. })
  99. rules = commonRules
  100. .map(r => r.replace("$bridge", bridge.name))
  101. .concat(rules)
  102. doc.set("rules", rules)
  103. fs.writeFileSync(
  104. `dist/${net.router}-${country}-IPMOYU-${bridge.name}.yaml`,
  105. doc.toString({
  106. lineWidth: 0
  107. })
  108. )
  109. }
  110. }
  111. const doc = parseDocument(template)
  112. doc.set("unified-delay", true)
  113. const proxies = doc.get("proxies")
  114. proxies.add(doc.createNode(bridge, { flow: true }))
  115. countryList
  116. .filter(country => country.abbr && country.abbr !== "-")
  117. .sort((a, b) => a.abbr.localeCompare(b.abbr))
  118. .forEach((country, i) => {
  119. const p = doc.createNode(
  120. {
  121. name: `${country.abbr}-${country.chnName}`,
  122. type: "socks5",
  123. server: "adv1.uipoxy.com",
  124. port: 3000,
  125. username: `haoge11_${country.id}_0_0_10_${randomstring.generate({
  126. length: 8,
  127. charset: "alphanumeric"
  128. })}_5_1`,
  129. password: "qaz112211",
  130. udp: true
  131. },
  132. { flow: true }
  133. )
  134. proxies.add(p)
  135. })
  136. // fs.writeFileSync(`dist/IPMOYU-GLOBAL.yaml`, doc.toString({ lineWidth: 0 }))