Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] 可否新增一个子命令用于输出或检测一个域名或 IP 的最终分流结果 #3311

Open
chshouyu opened this issue Apr 27, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@chshouyu
Copy link

chshouyu commented Apr 27, 2024

这个命令的用法大概是这样:

xray test www.google.com

这个命令会结合当前的 config.json 中的 routing.domainStrategyrouting.rules 以及 geosite.datgeoip.dat 等输出一个域名或 IP 详细的分流过程和最终的分流结果

这个命令大概有如下用途:

  1. 添加规则时用于验证规则是否符合预期结果
  2. 排查已有规则中的某个域名或 IP 是怎样分流的

这个命令大概的输出如下:

  1. 输出将会使用什么 DNS
  2. 输出当前依据的 domainStrategy
  3. 输出命中了 rules 中的第几个元素中的哪一条规则
  4. 输出输入的域名、IP 最终是直连还是代理以及使用哪个代理

由于目前添加、修改规则有点黑盒状态,需要添加完成后在日志或者浏览器中验证,如果有这样一个命令的话,就可以在添加、修改规则之前以一种离线的方式来验证,感觉对编写精确的规则配置会非常有用

@Fangliding
Copy link
Member

Fangliding commented Apr 27, 2024

curl -x http://127.0.0.1:1081 https://google.com
至于完全离线是不可能 ipondemand 之类的策略都需要解析dns之后才判断

@chshouyu
Copy link
Author

chshouyu commented Apr 27, 2024

确实,也就 domainStrategyAsIs 时或许可以离线。不过离线不是重点,主要是可以帮助用户排查一些分流问题,有点像白盒测试的感觉

@Fangliding
Copy link
Member

那日志完全可以做到吧

@chshouyu
Copy link
Author

chshouyu commented Apr 27, 2024

image

确实能得到一些分流信息,不过不够具体,比如用户想确定:

  • 一个域名或 IP 到底是 rules 中的哪一项配置匹配到的
  • 这个域名到底命中了 geosite 中的哪个规则集
  • 是用域名还是 IP 去匹配的
  • 有没有必要写这条规则
  • 规则的顺序需不需要调整

另外,有一个单独命令相比于使用日志查看有如下优势:

  • 不需要 reload 或 restart Xray,保存完配置文件就可以进行测试
  • 输出结果单一,不会受其他请求干扰

其实,基本等于一个剥离的分流单元测试功能

@vrnobody
Copy link
Contributor

直接在生产环境测路由不太好吧。单独开个core用来测路由就没其他信息干扰。
v1.8.10已经支持api替换routing,不需要重启core。

所以目前的问题只是debug log不够详细。

@Fangliding
Copy link
Member

问题是core设计的时候并没有给规则设置tag的功能 哪怕加也没办法指明规则是哪条(

@chshouyu
Copy link
Author

chshouyu commented Apr 28, 2024

@Fangliding 可以用数组索引呀,比如配置文件如下:

"routing": {
  "rules": [
    {
      "type": "field",
      "outboundTag": "Reject",
      "domain": ["geosite:category-ads-all"]
    },
    {
      "type": "field",
      "outboundTag": "Direct",
      "domain": [
        "geosite:private",
        "domain:baidu.com",
        "geosite:apple-cn",
        "geosite:google-cn",
        "geosite:tld-cn",
        "geosite:category-games@cn"
      ]
    },
    {
      "type": "field",
      "outboundTag": "Proxy",
      "domain": [
        "geosite:twitter",
        "geosite:geolocation-!cn"
      ]
    },
    {
      "type": "field",
      "outboundTag": "Direct",
      "domain": ["geosite:cn"]
    },
    {
      "type": "field",
      "outboundTag": "Proxy",
      "network": "tcp,udp"
    }
  ]
}

以 sing-box 举例,有一个 sing-box geosite 命令

image image

如果执行 xray test https://www.baidu.com,期望输出:

Current domainStrategy: AsIs
Use DNS: local
Match rule: rules[1]
Match domain: domain[1]: "domain:baidu.com"
Use outbound: Direct

如果执行 xray test https://twitter.com,期望输出:

Current domainStrategy: AsIs
Use DNS: 8.8.8.8
Match rule: rules[2]
Match domain: domain[0]: "geosite:twitter > twitter.com[11]" # 第 11 行
Use outbound: Singapore

如果执行 xray test https://www.google.com,期望输出:

Current domainStrategy: AsIs
Use DNS: 8.8.8.8
Match rule: rules[2]
Match domain: domain[1]: "geosite:geolocation-!cn > geosite:google > google.com[114]" # 第 114 行
Use outbound: Proxy

突然感觉叫做 xray fetch 命令可能更合适一些

@yuhan6665 yuhan6665 added the enhancement New feature or request label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants