之前介紹了使用 Cloudflare worker來進行客戶端 IP調查的小程式(https://diary.tw/archives/2182), 最近新增一些功能上來.
- 利用瀏覽器訪問時, 會加上完整的 html, 並增加了 Google Analytics 追蹤碼, 來記錄使用的次數.
- 若是利用非瀏覽器訪問時, 會直接輸出純文字 ip 而不會加上其他的內容, 例如: curl https://ip.diary.tw/
- 利用這個 geoplugin 這個免費的 API 功能來查找對應 IP的資訊, 請參考這個 API文件說明: https://www.geoplugin.com/webservices/json, 使用方式為 https://ip.diary.tw/?data=geo, 可以查找對應 IP的所在地與該地區使用貨幣與匯率. 輸出範例如下:
{
"geoplugin_request":"12.34.56.78",
"geoplugin_status":200,
"geoplugin_delay":"1ms",
"geoplugin_credit":"Some of the returned data includes GeoLite2 data created by MaxMind, available from <a href='https:\/\/www.maxmind.com'>https:\/\/www.maxmind.com<\/a>.",
"geoplugin_city":"New Taipei City",
"geoplugin_region":"New Taipei City",
"geoplugin_regionCode":"NWT",
"geoplugin_regionName":"New Taipei City",
"geoplugin_areaCode":"",
"geoplugin_dmaCode":"",
"geoplugin_countryCode":"TW",
"geoplugin_countryName":"Taiwan",
"geoplugin_inEU":0,
"geoplugin_euVATrate":false,
"geoplugin_continentCode":"AS",
"geoplugin_continentName":"Asia",
"geoplugin_latitude":"24.9466",
"geoplugin_longitude":"121.586",
"geoplugin_locationAccuracyRadius":"20",
"geoplugin_timezone":"Asia\/Taipei",
"geoplugin_currencyCode":"TWD",
"geoplugin_currencySymbol":"NT$",
"geoplugin_currencySymbol_UTF8":"NT$",
"geoplugin_currencyConverter":32.0408
}
請大家多加利用 IP查找小功具: https://ip.diary.tw
[2026/5/30 10:36]
由於原來的 ip geolocation service 已變成只有付費方案了如下:
{
"geoplugin_status":403,
"geoplugin_message": "geoPlugin API is no longer available for free use. To continue access, please upgrade to a paid plan",
"geoplugin_url": "https://www.geoplugin.com/subscription"
}
所以改用仍有 free tier 的另一個服務: https://ipgeolocation.io/, 免費就有一定的使用量可供應用, API 也簡單, 只需要註冊帳戶, 就可以拿 API Token 去訪問取得資訊, API 使用方式請參考:
https://ipgeolocation.io/documentation/ip-location-api.html
調整一下程式碼, 之後訪問 https://ip.diary.tw/?data=geo 時, 就可以拿到對應的回傳結果如下:
{
"ip": "12.34.56.78",
"location": {
"continent_code": "AS",
"continent_name": "Asia",
"country_code2": "TW",
"country_code3": "TWN",
"country_name": "Taiwan",
"country_name_official": "Republic of China",
"country_capital": "Taipei",
"state_prov": "New Taipei City",
"state_code": "TW-NWT",
"district": "Banqiao District",
"city": "New Taipei City",
"zipcode": "231",
"latitude": "24.97828",
"longitude": "121.53948",
"is_eu": false,
"country_flag": "https://ipgeolocation.io/static/flags/tw_64.png",
"geoname_id": "11697228",
"country_emoji": "🇹🇼"
},
"country_metadata": {
"calling_code": "+886",
"tld": ".tw",
"languages": [
"zh-TW",
"zh",
"nan",
"hak"
]
},
"currency": {
"code": "TWD",
"name": "New Taiwan Dollar",
"symbol": "NT$"
},
"asn": {
"as_number": "AS38841",
"organization": "kbro CO. Ltd.",
"country": "TW"
},
"time_zone": {
"name": "Asia/Taipei",
"offset": 8,
"offset_with_dst": 8,
"current_time": "2026-05-30 10:34:55.910+0800",
"current_time_unix": 1780108495.91,
"current_tz_abbreviation": "CST",
"current_tz_full_name": "Taipei Standard Time",
"standard_tz_abbreviation": "CST",
"standard_tz_full_name": "Taipei Standard Time",
"is_dst": false,
"dst_savings": 0,
"dst_exists": false,
"dst_tz_abbreviation": "",
"dst_tz_full_name": "",
"dst_start": {},
"dst_end": {}
}
}
資訊更多元更豐富了, 歡迎多加利用.