> For the complete documentation index, see [llms.txt](https://docs.ipcheck.ing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ipcheck.ing/knowledge-base/zh/getting-started/curl-api.md).

# 使用 Curl API

有时候你并不想要一个网页。你想在终端窗口里，或者脚本中，直接获取你的 IP 地址。MyIP 正好提供了这样一个纯文本端点。

在应用内，你可以点击 **curl** 横幅，在页面底部附近、页脚上方的产品条中。该面板标题为 **命令行 API**.

## 这些命令

在官方网站上， [ipcheck.ing](https://ipcheck.ing):

```bash
# 获取你机器的 IPv4 地址
curl 4.ipcheck.ing

# 获取你机器的 IPv6 地址
curl 6.ipcheck.ing

# 获取你机器偏好使用的任一地址
curl 64.ipcheck.ing
```

每个域名只通过一种协议响应，这正是前两个可靠的原因：

* `4.ipcheck.ing` 只能通过 IPv4 访问，因此它始终会报告你的 IPv4 地址。
* `6.ipcheck.ing` 只能通过 IPv6 访问，因此它始终会报告你的 IPv6 地址。
* `64.ipcheck.ing` 同时接受两种协议，因此会报告系统选择的那个——通常在可用时是 IPv6。

{% hint style="info" %}
如果 `curl 6.ipcheck.ing` 无法连接，那本身就是一个结果：你的网络可能没有可用的 IPv6。参见 [IPv4 与 IPv6](/knowledge-base/zh/concepts/ipv4-vs-ipv6.md).
{% endhint %}

## 添加地理位置

添加 `/geo` 到任意一个地址后，就会返回该地址的地理信息，而不只是地址本身：

```bash
curl 4.ipcheck.ing/geo
curl 6.ipcheck.ing/geo
curl 64.ipcheck.ing/geo
```

该 `/geo` 路径是可选的。只有在你只想要地址时，才可以不加它。

## 在脚本中使用

由于响应只有纯文本，没有别的内容，它可以直接放进 shell 脚本里：

```bash
# 将当前地址存入变量
MY_IP=$(curl -s 4.ipcheck.ing)
echo "当前地址：$MY_IP"
```

```bash
# 每分钟检查一次你的地址是否发生变化
while true; do
  date
  curl -s 4.ipcheck.ing
  sleep 60
done
```

该 `-s` 标志会让 curl 不输出自身进度，从而保持输出整洁。

常见用途包括：在开始备份任务前确认 VPN 已连接、监控家庭网络上的动态 IP 变化，或记录服务器正在使用哪个出口地址。

{% hint style="warning" %}
请合理控制调用频率。该服务是依靠捐赠的努力免费运行的——如果循环每隔几秒就发起一次请求，会被限流。对于几乎所有用途来说，每分钟一次已经足够。
{% endhint %}

## 在应用中检查同样的内容

命令行能提供的一切，在仪表板上也都有，而且更详细：

* 该 **IP 信息** 部分显示相同的地址，以及位置、ISP 和网络编号——参见 [阅读你的 IP 卡片](/knowledge-base/zh/getting-started/reading-your-ip-cards.md).
* 按 <kbd>q</kbd> 来查询你感兴趣的其他地址。

## 自托管实例

curl 域名是部署配置，而不是 MyIP 的固定组成部分。运行 MyIP 副本的人会为它选择自己的域名，面板会显示他们配置的内容。如果没有配置任何域名，面板会提示该功能不可用。

这意味着：

* 该 `4.ipcheck.ing`, `6.ipcheck.ing`，以及 `64.ipcheck.ing` 上述名称仅属于官方网站。
* 在自托管副本中，打开那里的 **命令行 API** 面板以查看该实例自己的命令。

关于如何运行你自己的副本，参见 [关于 MyIP](/knowledge-base/zh/faq/about.md).

## 相关页面

* [IP 信息](/knowledge-base/zh/connection-tools/ip-information.md)
* [为什么网站看到的 IP 不同？](/knowledge-base/zh/diagnose/why-do-sites-see-a-different-ip.md)
* [常见问题解答](/knowledge-base/zh/faq/general-faq.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.ipcheck.ing/knowledge-base/zh/getting-started/curl-api.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
