免費 IP 位址 API

在您的指令碼、應用程式和網站中使用 MonIP。免費、免註冊,也不需要 API 金鑰。

端點

GET https://monip.com/ip
以純文字傳回您的公用 IP 位址,非常適合指令碼使用。
GET https://monip.com/json
以 JSON 傳回您的 IP 位址及國家/地區、城市、座標、供應商與 ASN。
GET https://monip.com/api/lookup?q=8.8.8.8
以 JSON 傳回任何 IPv4 或 IPv6 位址或網域名稱的詳細資料。
GET https://monip.com/api/lookup?q=example.com&lang=zh-tw
加上 lang=… 即可取得其他語言的國家與城市名稱,例如 lang=de。

回應範例

$ curl "https://monip.com/api/lookup?q=8.8.8.8"
{
    "ip": "8.8.8.8",
    "version": 4,
    "type": "public",
    "hostname": "dns.google",
    "country_code": "US",
    "country": "美國",
    "region": "California",
    "city": "Mountain View",
    "latitude": 37.422,
    "longitude": -122.085,
    "asn": "AS15169",
    "isp": "Google LLC",
    "network": null,
    "tor": false
}

範例

# Bash
curl monip.com
curl -s monip.com/json | jq -r .country

# PowerShell
(Invoke-RestMethod https://monip.com/json).ip

# Python
import requests
print(requests.get("https://monip.com/api/lookup", params={"q": "8.8.8.8"}).json()["isp"])

// JavaScript
const me = await (await fetch("https://monip.com/json")).json();
console.log(me.ip, me.city, me.country);

限制與合理使用

每個 IP 位址每分鐘最多 60 次查詢。如需更多次數,請快取結果,因為 IP 位置很少變動。

已啟用 CORS,因此您可以直接在瀏覽器中透過 JavaScript 呼叫 API。

位置資料:IP Geolocation by DB-IP(CC BY 4.0)。若您在公開網站上使用此 API,請加上連往 MonIP.com 的連結。

想為網站加上現成的資訊框嗎?請使用免費的 IP 小工具。 →