[PR #6950] feat(hosts): clean IP scanner that saves working CDN IPs per ISP #6537

Open
opened 2026-11-02 04:09:29 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6950
Author: @Plus98ir
Created: 10/26/2026
Status: 🔄 Open

Base: main ← Head: feat/clean-ip-scanner


📝 Commits (10+)

  • 8c002ab feat(hosts): clean IP scanner that saves working Cloudflare IPs per ISP
  • 54e674c feat(hosts): full upload test and fragment finder for the clean IP scanner
  • 8ed6572 feat(hosts): clean IP scanner in five steps; warn when the visitor is on WARP/VPN
  • 6e41f32 fix(hosts): clean IP scanner rejects Cloudflare edge IPs that refuse the domain (error 1034)
  • cde7508 refactor(hosts): move the clean IP page's network lookup and step title into common.tsx
  • 1d651bf feat(hosts): show the datacenter city and country of each clean IP, with a country filter
  • 624fb48 fix(hosts): send empty lists, not null, in a clean IP report with no valid rows
  • f52b377 feat(hosts): scan your own IP list, find more IPs next to working ones, download CSV
  • b5f5eb5 style(hosts): keep the clean IP step titles readable on phones
  • cae5a37 chore(i18n): translate the clean IP scanner into every panel language

📊 Changes

51 files changed (+8182 additions, -0 deletions)

View changed files

➕ docs/content/docs/en/reference/api/clean-ip-scanner.mdx (+64 -0)
📝 docs/content/docs/en/reference/api/meta.json (+1 -0)
📝 docs/public/openapi.json (+636 -0)
📝 frontend/public/openapi.json (+636 -0)
📝 frontend/src/components/command-palette/CommandPalette.tsx (+1 -0)
📝 frontend/src/generated/examples.ts (+103 -0)
📝 frontend/src/generated/schemas.ts (+332 -0)
📝 frontend/src/generated/types.ts (+76 -0)
📝 frontend/src/generated/zod.ts (+86 -0)
📝 frontend/src/pages/api-docs/endpoints.ts (+49 -0)
➕ frontend/src/pages/clean-ip/CleanIpPage.css (+244 -0)
➕ frontend/src/pages/clean-ip/CleanIpPage.tsx (+1074 -0)
➕ frontend/src/pages/clean-ip/FragmentStep.tsx (+216 -0)
➕ frontend/src/pages/clean-ip/RangePicker.tsx (+82 -0)
➕ frontend/src/pages/clean-ip/colos.ts (+165 -0)
➕ frontend/src/pages/clean-ip/common.tsx (+57 -0)
➕ frontend/src/pages/clean-ip/report.ts (+47 -0)
➕ frontend/src/pages/clean-ip/scan.ts (+285 -0)
📝 frontend/src/routes/panelRoutes.tsx (+8 -0)
➕ frontend/src/test/clean-ip-colos.test.ts (+29 -0)

...and 31 more files

📄 Description

Summary

Adds a Clean IP scanner page (/clean-ip). It finds CDN edge IPs that work on a given ISP and saves them into a Host group as <group> · <ISP> (for example CDN · MCI), so each ISP's subscribers get IPs that work on their network. It supports Cloudflare, Fastly, Gcore and CloudFront.

Why

In censored networks (Iran, Russia, Turkmenistan, …) CDN-fronted inbounds only work through "clean" edge IPs. Which IPs are clean differs per ISP and changes over time. Admins currently run external scanners (CF-Clean-Scanner and similar) and copy the results into Hosts by hand. This page does it inside the panel, per ISP, and writes the result where 3x-ui already reads it: Host groups.

How it works (five steps on the page)

  1. Network: the page shows the ISP the visitor is on (ASN, org, short name such as MCI or MTN, from ipwho.is with ip-api.com as fallback). It warns when the visitor comes through WARP or a VPN, since the results would then be for the wrong network. CF-Connecting-IP is trusted only when the request really came from Cloudflare.
  2. Quick scan in the browser: the page probes edge IPs with a WebSocket handshake to wss://<ip>/ (the panel's CSP allows wss:). You pick the CDN and which of its ranges to scan, as in CF-Clean-Scanner. You can also paste your own IP list, find more IPs next to working ones, or download the result as CSV. Each working IP shows its datacenter (city and country) and can be filtered by country.
  3. Server-side check: the panel checks each IP that answered. On Cloudflare an IP can complete the TLS handshake and still refuse the domain with error 1034 or another 1xxx; those IPs are rejected.
  4. Full test (optional): a browser cannot do an upload test or fragmented TLS, so the page hands out a one-day command (curl … | python3 -, or PowerShell) to run on a device on that ISP.
    • The script uses the Python standard library only. It runs an upload test on the sampled IPs and on the quick scan's hits, then tests 26 Xray fragment settings (tlshello / 1-1, length and delay) against no fragment.
    • It reports back to the panel using only its token, and says why IPs failed (timeout, reset, certificate, …).
    • If the ISP blocks the panel's own domain, a second command reaches the panel through the fastest clean IP (curl --resolve), and the report goes through that IP too.
  5. Save: writes the chosen IPs as host rows into the ISP's Host group. When a fragment setting won, it also adds a TCP fragment finalMask to that group. A "Check saved IPs" / "Remove restricted" action re-checks rows saved earlier.

API (all documented in endpoints.ts, openapi.json and the docs MDX)

Route Purpose
GET /panel/api/cleanip/network ISP of the caller
GET /panel/api/cleanip/cdns CDNs and their range groups
POST /panel/api/cleanip/command make a one-day full-test command
GET /panel/api/cleanip/command/:token reports sent back so far
POST /panel/api/cleanip/verify server-side check: ok / restricted / unreachable
GET <base>cleanip/run/:token/script.py, POST <base>cleanip/run/:token/report public, token-only. They serve the script and accept its report

Commands live in memory only: at most 50, each valid for 24h, and lost on restart. The report endpoint accepts only its own token, caps the body at 256 KB, and validates every row (IPv4 only, known fragment shapes, bounded numbers).

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

  • Go tests (internal/web/service/cleanip_test.go) cover:
    • command input validation (a host that would break out of a Python literal is rejected);
    • every script placeholder gets filled;
    • report sanitizing;
    • expiry;
    • the CF-Connecting-IP trust rule;
    • Cloudflare 1xxx classification;
    • empty lists instead of null;
    • per-CDN and ticked-range sampling;
    • the clean-IP --resolve commands.
  • Python tests: some tests run the real embedded Python script (they are skipped when there is no Python 3). They cover the datacenter header parsing for each CDN, failure-reason counting, and that the report really goes through the pinned IP.
  • Frontend tests: target and range selection, fragment settings, datacenter codes.
  • Checks: make gen is clean, docs MDX regenerated, and go test ./internal/web/..., typecheck, lint, format and build all pass.
  • Production: running on two panels (Iran and Turkey, v3.11.0) since 2026-10-25, with real runs from Iranian ISPs including MCI. The hosts table and subscription output were compared before and after: rows outside the ISP groups are unchanged.

Screenshots / recordings

Steps 1-4 after a quick scan (local test panel, example domain):

clean IP scanner

The one-day full-test command:

full test command

Phone width:

clean IP scanner on a phone

Breaking changes

None. It is a new page and new routes. There is no DB migration: the scanner only writes ordinary Host rows through the existing host service.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6950 **Author:** [@Plus98ir](https://github.com/Plus98ir) **Created:** 10/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/clean-ip-scanner` --- ### 📝 Commits (10+) - [`8c002ab`](https://github.com/MHSanaei/3x-ui/commit/8c002ab993a558fdf29571eb22ec936159fc6725) feat(hosts): clean IP scanner that saves working Cloudflare IPs per ISP - [`54e674c`](https://github.com/MHSanaei/3x-ui/commit/54e674cb5bdf36b2b2cee3f8c9fa0422203e845d) feat(hosts): full upload test and fragment finder for the clean IP scanner - [`8ed6572`](https://github.com/MHSanaei/3x-ui/commit/8ed65725614fdf8f087d49a12866ebb446e4eb23) feat(hosts): clean IP scanner in five steps; warn when the visitor is on WARP/VPN - [`6e41f32`](https://github.com/MHSanaei/3x-ui/commit/6e41f328e2a185a7b91bc5cabf0b24ef4fad925b) fix(hosts): clean IP scanner rejects Cloudflare edge IPs that refuse the domain (error 1034) - [`cde7508`](https://github.com/MHSanaei/3x-ui/commit/cde7508e2c85df9f8f3fe3df107fa0b874f756a3) refactor(hosts): move the clean IP page's network lookup and step title into common.tsx - [`1d651bf`](https://github.com/MHSanaei/3x-ui/commit/1d651bf633e4e092ffe808160ae4af575e66d034) feat(hosts): show the datacenter city and country of each clean IP, with a country filter - [`624fb48`](https://github.com/MHSanaei/3x-ui/commit/624fb48326d9d5cdc77f5e6fd5581dd1bd4d9e1f) fix(hosts): send empty lists, not null, in a clean IP report with no valid rows - [`f52b377`](https://github.com/MHSanaei/3x-ui/commit/f52b377ba76e544881dc2a6a3a8c68bdb503438e) feat(hosts): scan your own IP list, find more IPs next to working ones, download CSV - [`b5f5eb5`](https://github.com/MHSanaei/3x-ui/commit/b5f5eb5f4b2f6e7d9a29437011de818a734501e0) style(hosts): keep the clean IP step titles readable on phones - [`cae5a37`](https://github.com/MHSanaei/3x-ui/commit/cae5a37b74b96b8736a8d1e525e1f616a15a6765) chore(i18n): translate the clean IP scanner into every panel language ### 📊 Changes **51 files changed** (+8182 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `docs/content/docs/en/reference/api/clean-ip-scanner.mdx` (+64 -0) 📝 `docs/content/docs/en/reference/api/meta.json` (+1 -0) 📝 `docs/public/openapi.json` (+636 -0) 📝 `frontend/public/openapi.json` (+636 -0) 📝 `frontend/src/components/command-palette/CommandPalette.tsx` (+1 -0) 📝 `frontend/src/generated/examples.ts` (+103 -0) 📝 `frontend/src/generated/schemas.ts` (+332 -0) 📝 `frontend/src/generated/types.ts` (+76 -0) 📝 `frontend/src/generated/zod.ts` (+86 -0) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+49 -0) ➕ `frontend/src/pages/clean-ip/CleanIpPage.css` (+244 -0) ➕ `frontend/src/pages/clean-ip/CleanIpPage.tsx` (+1074 -0) ➕ `frontend/src/pages/clean-ip/FragmentStep.tsx` (+216 -0) ➕ `frontend/src/pages/clean-ip/RangePicker.tsx` (+82 -0) ➕ `frontend/src/pages/clean-ip/colos.ts` (+165 -0) ➕ `frontend/src/pages/clean-ip/common.tsx` (+57 -0) ➕ `frontend/src/pages/clean-ip/report.ts` (+47 -0) ➕ `frontend/src/pages/clean-ip/scan.ts` (+285 -0) 📝 `frontend/src/routes/panelRoutes.tsx` (+8 -0) ➕ `frontend/src/test/clean-ip-colos.test.ts` (+29 -0) _...and 31 more files_ </details> ### 📄 Description ## Summary Adds a **Clean IP scanner** page (`/clean-ip`). It finds CDN edge IPs that work on a given ISP and saves them into a Host group as `<group> · <ISP>` (for example `CDN · MCI`), so each ISP's subscribers get IPs that work on their network. It supports Cloudflare, Fastly, Gcore and CloudFront. ## Why In censored networks (Iran, Russia, Turkmenistan, …) CDN-fronted inbounds only work through "clean" edge IPs. Which IPs are clean differs per ISP and changes over time. Admins currently run external scanners (CF-Clean-Scanner and similar) and copy the results into Hosts by hand. This page does it inside the panel, per ISP, and writes the result where 3x-ui already reads it: Host groups. ## How it works (five steps on the page) 1. **Network**: the page shows the ISP the visitor is on (ASN, org, short name such as MCI or MTN, from ipwho.is with ip-api.com as fallback). It warns when the visitor comes through WARP or a VPN, since the results would then be for the wrong network. `CF-Connecting-IP` is trusted only when the request really came from Cloudflare. 2. **Quick scan in the browser**: the page probes edge IPs with a WebSocket handshake to `wss://<ip>/` (the panel's CSP allows `wss:`). You pick the CDN and which of its ranges to scan, as in CF-Clean-Scanner. You can also paste your own IP list, find more IPs next to working ones, or download the result as CSV. Each working IP shows its datacenter (city and country) and can be filtered by country. 3. **Server-side check**: the panel checks each IP that answered. On Cloudflare an IP can complete the TLS handshake and still refuse the domain with error 1034 or another 1xxx; those IPs are rejected. 4. **Full test (optional)**: a browser cannot do an upload test or fragmented TLS, so the page hands out a **one-day command** (`curl … | python3 -`, or PowerShell) to run on a device on that ISP. - The script uses the Python standard library only. It runs an upload test on the sampled IPs and on the quick scan's hits, then tests 26 Xray `fragment` settings (`tlshello` / `1-1`, length and delay) against no fragment. - It reports back to the panel using only its token, and says why IPs failed (timeout, reset, certificate, …). - If the ISP blocks the panel's own domain, a second command reaches the panel through the fastest clean IP (`curl --resolve`), and the report goes through that IP too. 5. **Save**: writes the chosen IPs as host rows into the ISP's Host group. When a fragment setting won, it also adds a TCP `fragment` finalMask to that group. A "Check saved IPs" / "Remove restricted" action re-checks rows saved earlier. ### API (all documented in `endpoints.ts`, `openapi.json` and the docs MDX) | Route | Purpose | |---|---| | `GET /panel/api/cleanip/network` | ISP of the caller | | `GET /panel/api/cleanip/cdns` | CDNs and their range groups | | `POST /panel/api/cleanip/command` | make a one-day full-test command | | `GET /panel/api/cleanip/command/:token` | reports sent back so far | | `POST /panel/api/cleanip/verify` | server-side check: ok / restricted / unreachable | | `GET <base>cleanip/run/:token/script.py`, `POST <base>cleanip/run/:token/report` | public, token-only. They serve the script and accept its report | Commands live in memory only: at most 50, each valid for 24h, and lost on restart. The report endpoint accepts only its own token, caps the body at 256 KB, and validates every row (IPv4 only, known fragment shapes, bounded numbers). ## Type of change - [ ] Bug fix - [x] New feature - [ ] Refactoring (no behavior change) - [x] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [ ] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? - **Go tests** (`internal/web/service/cleanip_test.go`) cover: - command input validation (a host that would break out of a Python literal is rejected); - every script placeholder gets filled; - report sanitizing; - expiry; - the `CF-Connecting-IP` trust rule; - Cloudflare 1xxx classification; - empty lists instead of `null`; - per-CDN and ticked-range sampling; - the clean-IP `--resolve` commands. - **Python tests**: some tests run the real embedded Python script (they are skipped when there is no Python 3). They cover the datacenter header parsing for each CDN, failure-reason counting, and that the report really goes through the pinned IP. - **Frontend tests**: target and range selection, fragment settings, datacenter codes. - **Checks**: `make gen` is clean, docs MDX regenerated, and `go test ./internal/web/...`, typecheck, lint, format and build all pass. - **Production**: running on two panels (Iran and Turkey, v3.11.0) since 2026-10-25, with real runs from Iranian ISPs including MCI. The hosts table and subscription output were compared before and after: rows outside the ISP groups are unchanged. ## Screenshots / recordings Steps 1-4 after a quick scan (local test panel, example domain): ![clean IP scanner](https://raw.githubusercontent.com/Plus98ir/3x-ui/9b3442f5556fd9bac2925164c20072428277d57c/clean-ip-scan-top.png) The one-day full-test command: ![full test command](https://raw.githubusercontent.com/Plus98ir/3x-ui/9b3442f5556fd9bac2925164c20072428277d57c/clean-ip-command.png) Phone width: ![clean IP scanner on a phone](https://raw.githubusercontent.com/Plus98ir/3x-ui/9b3442f5556fd9bac2925164c20072428277d57c/clean-ip-phone.png) ## Breaking changes None. It is a new page and new routes. There is no DB migration: the scanner only writes ordinary Host rows through the existing host service. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6537
No description provided.