dart_ipify 套件提供了一種簡單的方式,使用 ipify API 取得您的公開 IP 位址或地理資訊。它支援多個平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,非常適合需要網路身分資訊的跨平台應用程式。該套件抽象了對 ipify 服務的 HTTP 請求,提供乾淨、易用的方法來取得 IP 資料。輕量且可靠,適用於需要即時 IP 查詢功能的應用程式。
適用情境
獲取使用者的公共IP位址
從IP地址獲取地理位置數據
跨平台網絡診斷
基於IP的用戶位置追蹤
應用程式中的自動IP記錄
主要特色
用於IP檢索的簡單API
支援透過IP定位位置
適用於所有主要平台
輕量且無依賴
使用安全的 HTTPS 連接
與 Flutter 應用輕鬆整合
適合對象
開發網路感知應用程式的開發者
需要用戶IP追蹤的應用程式
用於調試網路問題的工具
跨平台應用程式需要IP資訊
需要透過IP進行地理定位的服務
使用建議
依賴外部 ipify API 的可用性
免費方案可能有速率限制
地理位置的準確性取決於 ipify 的資料
無離線支援
需要互聯網連接才能運作
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
Dart Ipify
An unofficial client library for Ipify <https://www.ipify.org/>A Simple Public IP Address API, Likewise a geographical IP address details API.
About ipify
Using ipify is ridiculously simple. You can get your public IP directly or you can get the precise physical location of a given IP address. so if you only have as much as an IP address, you can still find out its geographical details.
This library makes getting your public IP address or the precise geographical details of a given IP address with the dart language extremely simple using Ipify's API.
Installation
dependencies:dart_ipify:^1.1.1
Usage
Using this library is very simple. Here's a simple example:
IP Address API
import'package:dart_ipify/dart_ipify.dart';
voidmain() async {
final ipv4 = awaitIpify.ipv4();
print(ipv4); // 98.207.254.136final ipv6 = awaitIpify.ipv64();
print(ipv6); // 98.207.254.136 or 2a00:1450:400f:80d::200efinal ipv4json = awaitIpify.ipv64(format: Format.JSON);
print(ipv4json); //{"ip":"98.207.254.136"} or {"ip":"2a00:1450:400f:80d::200e"}// The response type can be text, json or jsonp
}
IP Geolocation API
import'package:dart_ipify/dart_ipify.dart';
voidmain() async {
final mygeo = awaitIpify.geo('at_apiKeyxxxxxxxxxxxxxxxxxxxxxxx');
print(mygeo.location);
final somegeo = awaitIpify.geo('at_apiKeyxxxxxxxxxxxxxxxxxxxxxxx', ip: '8.8.8.8');
print(somegeo);
final balance = awaitIpify.balance('at_apiKeyxxxxxxxxxxxxxxxxxxxxxxx');
print(balance);
}