概述
IP 地图可视化功能可以生成包含代理 IP 地理位置的交互式 HTML 地图,使用 MapLibre GL JS 渲染,支持 Cyberpunk 风格的主题。
方式一:自动生成地图
在请求时启用 map_output 参数,自动生成地图文件。
使用示例
python
import cfspider
# 启用地图输出
response = cfspider.get(
"https://httpbin.org/ip",
cf_proxies="https://your-workers.dev",
map_output=True,
map_file="my_map.html"
)
# 自动生成包含 IP 信息的地图文件
参数说明
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
map_output |
bool |
False |
是否生成 IP 地图 HTML 文件 |
map_file |
str |
"cfspider_map.html" |
地图输出文件名 |
方式二:使用 IPMapCollector
手动收集 IP 记录并生成地图。
类定义
python
class IPMapCollector:
def add_record(
self,
url: str,
ip: str = None,
cf_colo: str = None,
cf_ray: str = None,
status_code: int = None,
response_time: float = None
)
def generate_map_html(output_file: str = "cfspider_map.html")
def clear_records()
使用示例
python
import cfspider
# 获取收集器
collector = cfspider.get_map_collector()
# 添加 IP 记录
collector.add_record(
url="https://example.com",
cf_colo="NRT", # 东京
cf_ray="8a1b2c3d4e5f-NRT",
status_code=200,
response_time=150.5
)
collector.add_record(
url="https://example.org",
cf_colo="SIN", # 新加坡
status_code=200,
response_time=200.3
)
# 生成地图
collector.generate_map_html("my_map.html")
# 清空记录
collector.clear_records()
便捷函数
cfspider.add_ip_record()
添加 IP 记录到全局收集器。
python
cfspider.add_ip_record(
url="https://example.com",
cf_colo="NRT",
status_code=200,
response_time=150.5
)
cfspider.generate_map_html()
生成地图 HTML 文件。
python
cfspider.generate_map_html("output_map.html")
cfspider.clear_map_records()
清空所有 IP 记录。
python
cfspider.clear_map_records()
支持的节点代码
CFspider 支持以下 Cloudflare 节点代码(主要节点):
亚洲
- NRT, HND, KIX(日本)
- HKG(香港)
- SIN(新加坡)
- ICN(首尔)
- TPE(台北)
- BKK(曼谷)
- KUL(吉隆坡)
- BOM, DEL(印度)
- SYD, MEL(澳大利亚)
北美
- SJC, LAX, SEA, DFW, ORD, IAD, EWR, MIA, ATL(美国)
- YYZ, YVR(加拿大)
欧洲
- LHR(伦敦)
- CDG(巴黎)
- FRA(法兰克福)
- AMS(阿姆斯特丹)
- ZRH(苏黎世)
- MAD(马德里)
- MXP(米兰)
- WAW(华沙)
- ARN(斯德哥尔摩)
其他地区
- GRU(圣保罗)
- DXB(迪拜)
- JNB(约翰内斯堡)
地图特性
- 交互式地图:支持缩放、拖拽、点击查看详情
- Cyberpunk 风格:霓虹色彩主题,视觉效果炫酷
- 节点标记:每个 Cloudflare 节点显示为标记点
- 详细信息:点击标记可查看 URL、状态码、响应时间等
- 统计信息:显示总请求数、成功数、平均响应时间等