Skip to content

feat: filter proxies by country via ?area=CN (#84, #177) - #233

Merged
Germey merged 2 commits into
masterfrom
feature/geo-area
Jul 4, 2026
Merged

feat: filter proxies by country via ?area=CN (#84, #177)#233
Germey merged 2 commits into
masterfrom
feature/geo-area

Conversation

@Germey

@Germey Germey commented Jul 4, 2026

Copy link
Copy Markdown
Member

背景

Issue 收敛计划 Phase 4b(增强:按国家/地区筛选代理),对应 #84(按国家区分)和 #177(筛选国内 IP)。

⚠️ 本 PR 是 stacked PR,链路为 security/harden-api(#231) → feature/random-count(#232) → 本分支。建议 #231#232 → 本 PR 顺序合并,GitHub 会随上游合并自动重定向 base。

亮点:把一个「僵尸依赖」变成功能

maxminddb_geolite2 早已在 requirements.txt 里,但从未被使用。本 PR 用它实现离线 IP→国家解析,无需新增依赖。

改动

  • 新增 proxypool/utils/geo.pyget_country_iso(ip) 基于内置 GeoLite2 库返回 ISO 国家码;库缺失或解析失败时安全降级返回 None(不影响其他功能)。
  • processors/server.py/random/all 新增 area 参数,按国家码筛选(大小写不敏感),可与 countkey 组合。
  • README.md:补充 area 用法。

用法

GET /random?area=CN          # 随机一个国内代理  (#177)
GET /all?area=CN             # 所有国内代理
GET /random?area=US&count=5  # 5 个美国代理

验证

  • server.py / geo.py 编译通过。
  • 本地实测(GeoLite2):8.8.8.8 → US114.114.114.114 → CNfilter(area=CN) 只保留 114.114.114.114filter(area=US) 只保留 8.8.8.8
  • area 参数时行为完全不变。

关联 issue

@Germey
Germey changed the base branch from feature/random-count to master July 4, 2026 08:46
Germey added 2 commits July 4, 2026 16:47
- redis: add RedisClient.randoms(count, ...) which prefers max-score proxies and falls back to rank, returning a de-duplicated random sample

- server: /random accepts a count parameter and returns N random proxies (one per line); count<=1 keeps the original single-proxy behavior; works with key too

- README: document the new count parameter

Closes #194
- utils/geo: add get_country_iso() backed by the bundled GeoLite2 db (previously an unused dependency); fails safe to None if unavailable

- server: /random and /all accept an area parameter (country iso code) to return only proxies from that country; combines with count and key

- README: document the area parameter

Closes #84, Closes #177
@Germey
Germey force-pushed the feature/geo-area branch from 5cb9158 to 8cd8a6e Compare July 4, 2026 08:47
@Germey
Germey merged commit b915026 into master Jul 4, 2026
@Germey
Germey deleted the feature/geo-area branch July 4, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

可以筛选国内的ip吗 最好能增加ip的地址位置,以国家区分

1 participant