# 如何轮换 4G 移动代理 IP

> 通过链接、API 或定时器轮换专用 4G 移动代理 IP：约 5–15 秒获得新 IP，每 30 秒最多轮换一次，支持 429 处理。端口起价 $2.63/天，无需 KYC，支持加密货币支付。

- URL: https://namelessproxy.com/zh/guides/rotate-mobile-ip/
- 最后更新: 2026-10-05
- Publisher: Nameless Proxy (https://namelessproxy.com)

轮换链接、API 调用、自动定时器、30 秒限制及如何确认 IP 已更换。包含 bash 和 Python 脚本示例。

**快速答案 — 如何轮换 4G 移动代理的 IP？**

打开端口的轮换链接 `https://namelessproxy.com/api/v1/mobile/{port}/rotate?key=API_KEY`，用 POST 和 Bearer API 密钥调用相同端点，或设置定时器。**Nameless Proxy** 是一家注重隐私、无需 KYC 的代理服务商，约 5–15 秒内为端口分配新的运营商 IP，每个端口最多每 30 秒轮换一次。专用端口起价 $2.63/天。无需 KYC — 无需身份证、自拍或文件。支持加密货币支付。

## 轮换概览

| 属性 | 值 |
| --- | --- |
| 轮换链接 | `GET https://namelessproxy.com/api/v1/mobile/{port}/rotate?key=API_KEY` |
| API 调用 | `POST /v1/mobile/{portId}/rotate` 与 `Authorization: Bearer API_KEY` |
| 计时器 | 每 2 到 1,440 分钟 |
| 每次切换时间 | 大约 5–15 秒 |
| 限制 | 每个端口每 30 秒允许一次切换；否则 `429 rotation_too_soon` 与 `Retry-After` |
| 密钥权限范围 | `proxies`（添加 `read` 可列出 IP 历史） |
| 响应 | `ip`、`previousIp`、`rotatedAt`、`nextRotationAvailableAt` |
| IP 历史 | 保存 30 天 |

## 切换前我需要准备什么？

您需要从客户区获取三样东西：

- **端口 ID**，以 `mob_` 开头，例如 `mob_2v8k1q`。
- **端口的终端和凭证**（主机、端口、用户名、密码），用于发送流量和检查 IP。
- **具有 `proxies` 权限范围的 API 密钥。**完整密钥只显示一次，我们只存储哈希。添加 `read` 可列出 IP 历史。

切换适用于[专用 4G/5G 端口](https://namelessproxy.com/zh/mobile-proxies/)，不适用于按 GB 计费的旋转移动流量。

## 如何使用切换链接进行切换？

发送 GET 请求到 `https://namelessproxy.com/api/v1/mobile/{port}/rotate?key=API_KEY`，填入您的端口 ID 和 API 密钥。可通过浏览器书签、curl 或任何 HTTP 工具使用。添加 `&format=text` 可获取纯文本格式的新 IP，而非 JSON。调用在调制解调器重新连接后返回，最多等待一分钟以免超时。

下面的脚本从模板构建链接，并在 `429` 后重试。

*rotate.sh：带重试的切换链接*

```bash
#!/usr/bin/env bash
# Rotate a dedicated port with its rotation link, retrying after 429.
set -euo pipefail
PORT_ID="PORT_ID"      # e.g. mob_2v8k1q
API_KEY="API_KEY"      # API key with the "proxies" scope

TEMPLATE="https://namelessproxy.com/api/v1/mobile/{port}/rotate?key=API_KEY"
URL="${TEMPLATE/"{port}"/$PORT_ID}"
URL="${URL/API_KEY/$API_KEY}&format=text"   # format=text: the new IP as plain text

HDRS=$(mktemp); BODY=$(mktemp)
for attempt in 1 2 3; do
  STATUS=$(curl -sS --max-time 60 -D "$HDRS" -o "$BODY" -w '%{http_code}' "$URL")
  if [ "$STATUS" = "200" ]; then
    echo "New IP: $(cat "$BODY")"; exit 0
  fi
  if [ "$STATUS" = "429" ]; then
    WAIT=$(grep -i '^retry-after:' "$HDRS" | tr -dc '0-9'); WAIT=${WAIT:-30}
    echo "Too soon; retrying in ${WAIT}s"; sleep "$WAIT"; continue
  fi
  echo "Rotation failed (HTTP $STATUS):"; cat "$BODY"; exit 1
done
exit 1
```

> **链接包含您的密钥** 任何拥有该链接的人都能切换您的端口，且 URL 会出现在浏览器历史和服务器日志中。请使用仅含 proxies 权限的密钥，切勿分享链接，若泄露请在客户区撤销密钥。

## 如何使用 API 进行切换？

向同一路径发送 `POST`，不带查询字符串，密钥放在 `Authorization: Bearer` 头部。这样密钥不会出现在 URL 中。成功调用返回新 IP、之前的 IP、切换时间及下一次切换的最早时间。

*响应 (200)*

```json
{
  "ip": "203.0.113.57",
  "previousIp": "203.0.113.12",
  "rotatedAt": "2026-10-05T14:03:11Z",
  "nextRotationAvailableAt": "2026-10-05T14:03:41Z"
}
```

*rotate.py：切换，处理 429，通过端口检查 IP*

```python
# pip install requests
import time
import requests

API_KEY = "API_KEY"     # API key with the "proxies" scope
PORT_ID = "PORT_ID"     # e.g. mob_2v8k1q
PROXY = "http://USERNAME:PASSWORD@HOST:PORT"   # the port's endpoint, from the client area

TEMPLATE = "https://namelessproxy.com/api/v1/mobile/{port}/rotate?key=API_KEY"
ROTATE_URL = TEMPLATE.replace("{port}", PORT_ID).split("?")[0]   # POST: key goes in the header
HEADERS = {"Authorization": f"Bearer {API_KEY}"}

def exit_ip():
    return requests.get("https://api.ipify.org",
                        proxies={"http": PROXY, "https": PROXY}, timeout=30).text

def rotate(max_attempts=3):
    for _ in range(max_attempts):
        r = requests.post(ROTATE_URL, headers=HEADERS, timeout=60)   # takes ~5-15 s
        if r.status_code == 200:
            return r.json()   # ip, previousIp, rotatedAt, nextRotationAvailableAt
        if r.status_code == 429:   # rotation_too_soon or rate_limited
            wait = int(r.headers.get("Retry-After", "30"))
            print(f"{r.json()['error']['code']}: waiting {wait} s")
            time.sleep(wait)
            continue
        r.raise_for_status()      # 401, 403 (missing scope), 404, 409 port_not_active
    raise RuntimeError("Rotation did not succeed")

before = exit_ip()
result = rotate()
print(f"{before} -> {result['ip']}; next rotation from {result['nextRotationAvailableAt']}")
if result["ip"] == result["previousIp"]:
    print("Same IP: the carrier handed it back. Try again after the 30 s limit.")
print("Seen through the proxy:", exit_ip())
```

## 如果我旋转太频繁会怎样？

当上次旋转不到 30 秒时，API 会以错误代码 `rotation_too_soon` 回复 `429`。`Retry-After` 头和 `error.details.retryAfter` 字段会告诉你需要等待的秒数。上一次成功旋转的 `nextRotationAvailableAt` 字段也会提前告诉你相同的信息。

## 如何设置定时自动旋转？

在客户端区域或通过 `PATCH` 调用，将端口的旋转模式设置为 `interval`，时间范围为 2 到 1,440 分钟。设置回 `manual` 可停止旋转。相同脚本会读取端口的 IP 历史，显示每个 IP 的起止时间及触发更换的原因：手动、链接、间隔、迁移或运营商。如果调用返回 `403`，说明密钥缺少作用域；请使用 `read` 和 `proxies` 创建一个。

*定时开，定时关，IP 历史*

```bash
PORT_ID="PORT_ID"      # e.g. mob_2v8k1q
API_KEY="API_KEY"      # scopes: proxies (+ read for the history)
TEMPLATE="https://namelessproxy.com/api/v1/mobile/{port}/rotate?key=API_KEY"
API_BASE="${TEMPLATE%%/v1/*}/v1"     # the API root, taken from the rotation link

# Rotate automatically every 10 minutes (allowed: 2 to 1,440)
curl -sS -X PATCH "$API_BASE/mobile/$PORT_ID" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"rotation": {"mode": "interval", "intervalMinutes": 10}}'

# Back to manual rotation
curl -sS -X PATCH "$API_BASE/mobile/$PORT_ID" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"rotation": {"mode": "manual", "intervalMinutes": null}}'

# The last IPs of the port (history is kept 30 days)
curl -sS "$API_BASE/mobile/$PORT_ID/ip-history?perPage=10" \
  -H "Authorization: Bearer $API_KEY"
```

## 为什么我有时会获得相同的 IP？

移动运营商通过运营商级 NAT 在多个用户间共享公共 IPv4 地址，因此调制解调器可能会再次分配相同的地址。Cloudflare 指出一个 IPv4 地址可能代表数百甚至数千用户。比较响应中的 `ip` 和 `previousIp`，如果相同，请在 30 秒后再次旋转。

## 移动 IP 旋转的最佳实践是什么？

- **旋转时暂停流量。** 当调制解调器重新连接时，端口上的打开连接会断开，因此请在任务间旋转。
- **遵守限制。** 读取 `Retry-After` 或 `nextRotationAvailableAt`，不要循环重试。
- **通过端口检查 IP，** 不仅仅依赖 API 响应。
- **处理 `409 port_not_active`：** 端口已过期、暂停或仍在设置中。
- **迁移后重新读取端点：** 主机、端口和凭据可能会变更。
- **需要大量 IP？** 租用多个端口；每个端口一次只有一个 IP。

请将旋转用于合法用途，如应用测试、广告检查和管理客户账户。规避封禁和虚假账户行为被[可接受使用政策](https://namelessproxy.com/zh/acceptable-use/)]禁止。

## 常见问题

### 移动 IP 旋转需要多长时间？

通常为 5 到 15 秒。调制解调器重新连接运营商以获取新 IP，API 调用在完成后返回。请将 HTTP 超时设置约为一分钟，以避免慢速重连被误报为错误，同时暂停工作线程。

### 我能否每 30 秒内旋转多次？

不能。每个端口允许每 30 秒旋转一次；更快调用会收到带有 `Retry-After` 头的 `429 rotation_too_soon`。限制是按端口计算，若需每分钟更多新鲜 IP，请运行多个端口轮流旋转，或使用按 GB 计费的旋转移动流量。

### 每次旋转会额外收费吗？

不会。通过链接、API 或定时器旋转包含在所有专用端口套餐内，价格表中无旋转单次收费。端口按天、周或月计费，起价为 $2.63/天，附带 无限流量，无每日上限。

### 分享我的旋转链接安全吗？

不安全。链接包含你的 API 密钥，任何持有者都能在你使用时旋转你的端口。请给团队成员分配独立端口。创建密钥时仅赋予 `proxies` 作用域，这样泄露链接无法下单，若泄露请立即撤销。

### 新 IP 会一直在同一城市吗？

端口保持在同一运营商和调制解调器，但运营商会从区域池中选择 IP。因此 IP 检测工具可能会将新 IP 定位到附近城市。若想更改国家、运营商或城市，请在客户端区域迁移端口。

### 为什么旋转失败并返回 401 或 403？

`401` 表示密钥缺失、错误或已撤销：请检查链接或 Bearer 头中是否包含完整密钥。`403` 表示密钥缺少 `proxies` 作用域，或账户被暂停。请创建具有正确作用域的新密钥；旧密钥的密钥串无法再次显示。

## 来源

1. [一个 IP 地址，多个用户：检测 CGNAT 以减少附带影响](https://blog.cloudflare.com/detecting-cgn-to-reduce-collateral-damage/) — Cloudflare Blog (2026-10-05)
2. [RFC 6888，运营商级 NAT (CGNs) 的通用要求](https://www.rfc-editor.org/rfc/rfc6888) — RFC Editor (2026-10-05)

**租用专用 4G/5G 端口** 起价 $2.63/天，支持通过链接、API 或定时器旋转。无需 KYC — 无需身份证、自拍或文件。支持加密货币支付。 [获取4G/5G代理——起价$2.63/天](https://namelessproxy.com/zh/pricing/) · [4G/5G 代理 — $2.63/天 起](https://namelessproxy.com/zh/mobile-proxies/)

---

Nameless Proxy: Nameless Proxy 是一家隐私优先、无需 KYC 的代理提供商：轮换住宅代理和 4G/5G 移动代理，账号编号登录，支持加密货币支付（Bitcoin、USDT、USDC）。住宅代理起价 US$0.53/GB。
