分類
好用軟體

IP調查小程式-功能新增

之前介紹了使用 Cloudflare worker來進行客戶端 IP調查的小程式(https://diary.tw/archives/2182), 最近新增一些功能上來.

  1. 利用瀏覽器訪問時, 會加上完整的 html, 並增加了 Google Analytics 追蹤碼, 來記錄使用的次數.
  2. 若是利用非瀏覽器訪問時, 會直接輸出純文字 ip 而不會加上其他的內容, 例如: curl https://ip.diary.tw/
  3. 利用這個 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": {}
  }
}

資訊更多元更豐富了, 歡迎多加利用.

[2026/8/17 7:20]

原來在 Cloudflare 中有 request.cf 變數(可參考: https://developers.cloudflare.com/workers/runtime-apis/request/),裡面也有對應的地理資訊,新增 https://ip.diary.tw/?data=geo2 範例資料如下:

{
  "httpProtocol": "HTTP/2",
  "clientAcceptEncoding": "gzip, deflate, br",
  "requestPriority": "weight=42;exclusive=0;group=0;group-weight=0",
  "edgeRequestKeepAliveStatus": 1,
  "requestHeaderNames": {},
  "clientTcpRtt": 12,
  "clientQuicRtt": 0,
  "colo": "TPE",
  "asn": 38841,
  "asOrganization": "kbro CO. Ltd.",
  "country": "TW",
  "isEUCountry": false,
  "city": "Banqiao",
  "continent": "AS",
  "region": "Taipei",
  "regionCode": "TPE",
  "timezone": "Asia/Taipei",
  "longitude": "121.46719",
  "latitude": "25.01427",
  "tlsVersion": "TLSv1.3",
  "tlsCipher": "AEAD-AES128-GCM-SHA256",
  "tlsClientRandom": "iZQjjbMHDvqj7bV9mGrvFOLCfcVTM7EfuEhmcEf6biE=",
  "tlsClientCiphersSha1": "Ycpx9ze2EIngjFvfLFng3z8MFzM=",
  "tlsClientExtensionsSha1": "fmoiUXxub2JA3Bd4T7jJ6OCQJ/s=",
  "tlsClientExtensionsSha1Le": "75rYBxmWw7lFoVazIKaJJGtd1xc=",
  "tlsExportedAuthenticator": {
    "clientHandshake": "d9433345ccb61cda32fc50991665f17c63e3f1d63d7bf8ef016c552543ee0920",
    "serverHandshake": "948cc32b3413616b0a331ed886a26abca9625c85e753afb790711648aa0497d4",
    "clientFinished": "90eb15c16b0812c9168d858e7d02b142a8358b1480766efb85b37479d74a41fa",
    "serverFinished": "1df4bd5176a49fbfd4f40e2b04827eed5e0a32ef520a1d4934cabd915f2ea9b4"
  },
  "tlsClientHelloLength": "1885",
  "tlsClientAuth": {
    "certPresented": "0",
    "certVerified": "NONE",
    "certRevoked": "0",
    "certIssuerDN": "",
    "certSubjectDN": "",
    "certIssuerDNRFC2253": "",
    "certSubjectDNRFC2253": "",
    "certIssuerDNLegacy": "",
    "certSubjectDNLegacy": "",
    "certSerial": "",
    "certIssuerSerial": "",
    "certSKI": "",
    "certIssuerSKI": "",
    "certFingerprintSHA1": "",
    "certFingerprintSHA256": "",
    "certNotBefore": "",
    "certNotAfter": "",
    "certRFC9440": "",
    "certRFC9440TooLarge": false,
    "certChainRFC9440": "",
    "certChainRFC9440TooLarge": false
  },
  "verifiedBotCategory": "",
  "edgeL4": {
    "deliveryRate": 284711
  }
}

 

大家也可以多加利用!

-- viewing this page|-- online sitewide

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

Exit mobile version