ipweb.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. const country = "US"
  7. const groupSize = 1
  8. const proxyNumEachGroup = 2
  9. const nets = [
  10. {
  11. router: "192.168.6.1",
  12. subnets: ["192.168.10"]
  13. },
  14. {
  15. router: "192.168.7.1",
  16. subnets: ["192.168.11", "192.168.12"]
  17. },
  18. {
  19. router: "192.168.8.1",
  20. subnets: ["192.168.13", "192.168.14"]
  21. }
  22. ]
  23. const { data: template, config } = await axios.get(
  24. "http://192.168.50.47:25500/sub",
  25. {
  26. params: {
  27. target: "clash",
  28. url: "http://192.168.50.46:3000/download/collection/all?target=ClashMeta",
  29. insert: false,
  30. config: "https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_NoAuto.ini",
  31. emoji: true,
  32. list: false,
  33. xudp: false,
  34. udp: false,
  35. tfo: false,
  36. expand: true,
  37. scv: true,
  38. fdn: false,
  39. new_name: true
  40. }
  41. }
  42. )
  43. for (let bridge of bridges) {
  44. for (let net of nets) {
  45. const ips = net.subnets.flatMap(subnet => {
  46. return Array.from({ length: 200 }, (_, i) => `${subnet}.${i + 50}`)
  47. })
  48. const doc = parseDocument(template)
  49. doc.set("unified-delay", true)
  50. const proxies = doc.get("proxies")
  51. const proxyGroups = doc.get("proxy-groups")
  52. let rules = doc.get("rules").items
  53. proxies.add(doc.createNode(bridge, { flow: true }))
  54. let c = 0,
  55. g = 0
  56. ips.forEach((ip, i) => {
  57. if (i % groupSize === 0) {
  58. const groupProxies = Array.from(
  59. { length: proxyNumEachGroup },
  60. (_, j) => {
  61. const p = doc.createNode(
  62. {
  63. name: `${country}-${++c}`,
  64. type: "socks5",
  65. server: "gate1.ipweb.cc",
  66. port: 7778,
  67. username: `B_37678_${country}___5_${randomstring.generate(
  68. { length: 8, charset: "alphanumeric" }
  69. )}`,
  70. password: "123456",
  71. "dialer-proxy": bridge.name
  72. },
  73. { flow: true }
  74. )
  75. proxies.add(p)
  76. return p
  77. }
  78. )
  79. const group = doc.createNode(
  80. {
  81. name: `${country}-GROUP-${++g}`,
  82. type: "url-test",
  83. url: "http://www.gstatic.com/generate_204",
  84. interval: 150,
  85. tolerance: 50,
  86. proxies: groupProxies.map(p => p.get("name"))
  87. },
  88. { flow: true }
  89. )
  90. proxyGroups.add(group)
  91. }
  92. rules.unshift(
  93. `SRC-IP-CIDR,${ip}/32,${proxyGroups
  94. .get(proxyGroups.items.length - 1)
  95. .get("name")}`
  96. )
  97. })
  98. rules = [
  99. "DOMAIN-SUFFIX,izouma.com,DIRECT",
  100. "IP-CIDR,47.98.225.28/32,DIRECT",
  101. "IP-CIDR,8.149.128.251/32,DIRECT",
  102. "DOMAIN-SUFFIX,baidu.com,DIRECT",
  103. "DOMAIN-SUFFIX,aliyuncs.com,DIRECT"
  104. ].concat(rules)
  105. doc.set("rules", rules)
  106. fs.writeFileSync(
  107. `dist/${net.router}-${country}-IPWEB-${bridge.name}.yaml`,
  108. doc.toString({
  109. lineWidth: 0
  110. })
  111. )
  112. }
  113. }