> 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-tw/getting-started/curl-api.md).

# 使用 Curl API

直接在終端機用 curl 取得你的公網 IP 位址——IPv4、IPv6，或是你的裝置偏好的類型，並可選擇地理位置資訊。

有時你不想要一個網頁。你想在終端機視窗中，或在腳本裡看到你的 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-tw/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-tw/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-tw/faq/about.md).

## 相關頁面

* [IP 資訊](/knowledge-base/zh-tw/connection-tools/ip-information.md)
* [為什麼網站看到的 IP 不同？](/knowledge-base/zh-tw/diagnose/why-do-sites-see-a-different-ip.md)
* [一般常見問題](/knowledge-base/zh-tw/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-tw/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.
