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);
}