IP2Location.io Dart SDK is a Dart package for retrieving IPv4 and IPv6 geolocation, network and IP intelligence data through the IP2Location.io API. It also supports domain WHOIS lookup and hosted domain lookup. Use its asynchronous lookup methods to integrate IP and domain information into Dart applications without building HTTP requests manually.
Quick links: Get an API key · Developer documentation · API reference · pub.dev package
- IPv4 and IPv6 geolocation: Retrieve available country, region, district, city, coordinates and postal-code information.
- Network and ASN information: Look up ASN, autonomous system, ISP, associated domains, connection/usage type and related data where included in your plan.
- Time zone and localization data: Access time zone and available daylight saving information; request translated continent, country, region and city names on Plus and Security plans.
- Proxy and security signals: Check available proxy, VPN, Tor, data center, web crawler, AI crawler and other indicators, including fraud score where provided by your plan.
- Additional IP intelligence: Access available mobile operator (MCC/MNC), country, weather/elevation and advertising category fields.
- Domain WHOIS lookup: Retrieve available domain registration information, such as dates, registrar, statuses, nameservers and contact data.
- Internationalized domain and URL utilities: Convert Unicode domain names to/from Punycode, extract a domain name from a URL and obtain a domain extension.
- Hosted domains: Retrieve domains hosted on an IPv4 or IPv6 address, including paginated results.
- Asynchronous Dart API: Perform network lookups using
Future<Map<String, dynamic>>andasync/await.
Plan availability: Fields and security signals vary by API plan and queried IP address. See plan details and the Dart API response field reference.
The Dart SDK API reference documents four classes:
| Class | Description |
|---|---|
Configuration |
Holds the API key for SDK lookups. |
IPGeolocation |
Performs IPv4/IPv6 geolocation and available network/security data lookups. |
DomainWhois |
Performs WHOIS lookups and provides domain/Punycode utilities. |
HostedDomain |
Retrieves hosted-domain lists for IP addresses with optional pagination. |
IP2Location.io offers keyless IP geolocation requests and a Free plan with an API key:
| API service | Keyless (no API key) | Free plan (with API key) |
|---|---|---|
| IP Geolocation API | 1,000 queries/day | 50,000 queries/month |
| Domain WHOIS API | — | 500 queries/month |
| Hosted Domain API | — | 50 queries/month |
- Keyless access: No registration required for keyless IP geolocation requests made directly to the REST API. The quota resets daily at 00:00 UTC. The Dart SDK examples below use an API key; keyless use is not a documented Dart SDK configuration mode.
- Free plan: Register for a free API key to use the monthly allowances above, subject to the respective quotas.
- Attribution: Keyless and Free-plan usage requires attribution; follow the pricing page for the applicable requirements.
- Paid plans: Refer to the pricing page for current paid-plan query limits, features and pricing.
For keyless requests, authentication and rate limiting, see the IP Geolocation REST API documentation.
- Dart SDK 3.8.2 or later (below 4.0.0), as declared by this package's
pubspec.yaml. - Dart's pub package manager.
- An IP2Location.io API key for SDK lookups (free signup available).
- Network access to the relevant API services.
The package declares http and punycoder as dependencies. Unlike the PHP SDK, no PHP extensions or Composer setup are needed.
In your Dart project, install the package:
dart pub add ip2location_ioSet your API key as an environment variable instead of hard-coding it:
# Linux / macOS
export IP2LOCATION_API_KEY='YOUR_API_KEY'REM Windows Command Prompt
set IP2LOCATION_API_KEY=YOUR_API_KEYYou can also supply it through your environment or deployment configuration. The examples read it with Platform.environment.
Create bin/lookup.dart inside your Dart project:
import 'dart:io';
import 'package:ip2location_io/configuration.dart';
import 'package:ip2location_io/ip_geolocation.dart';
Future<void> main() async {
final apiKey = Platform.environment['IP2LOCATION_API_KEY'];
if (apiKey == null || apiKey.isEmpty) {
stderr.writeln('Set the IP2LOCATION_API_KEY environment variable.');
exitCode = 1;
return;
}
final config = Configuration(apiKey);
final geo = IPGeolocation(config);
try {
final result = await geo.lookUp('8.8.8.8');
stdout.writeln('Country: ${result['country_name'] ?? 'N/A'}');
stdout.writeln('City: ${result['city_name'] ?? 'N/A'}');
stdout.writeln('ASN: ${result['asn'] ?? 'N/A'}');
} catch (e) {
stderr.writeln('Lookup failed: $e');
exitCode = 1;
}
}Run it from the project root:
dart run bin/lookup.dartSuccessful results are written to standard output. CLI errors are written to standard error and use exit code 1; successful execution exits with code 0. These conventions are for executable examples, not reusable application/library methods. The returned map fields depend on your API plan and the IP address. See the geolocation response fields.
Dart network lookups use await and return a Map<String, dynamic>. Access JSON response fields using keys such as result['country_name']; nested values can be maps. Always handle missing or nullable optional fields.
All API lookup snippets below are intended to run inside an async function after importing their class libraries and creating config as in the quickstart. For standalone command-line scripts, apply the same try/catch, stderr.writeln() and exitCode = 1 convention used above.
The optional second argument to IPGeolocation.lookUp(ip, language) accepts a language code. Translated continent, country, region and city names are available on Plus and Security plans.
final geo = IPGeolocation(config);
try {
final result = await geo.lookUp('8.8.8.8', 'es');
stdout.writeln(result);
} catch (e) {
stderr.writeln('Lookup failed: $e');
exitCode = 1;
}Security signals depend on your plan. Use map-key access and check whether the nested proxy object exists before reading its fields.
final geo = IPGeolocation(config);
try {
final result = await geo.lookUp('8.8.8.8');
final proxy = result['proxy'];
if (proxy is Map) {
stdout.writeln('VPN indicator: ${proxy['is_vpn'] ?? 'N/A'}');
stdout.writeln('Tor indicator: ${proxy['is_tor'] ?? 'N/A'}');
} else {
stdout.writeln('Proxy details unavailable for this response.');
}
} catch (e) {
stderr.writeln('Lookup failed: $e');
exitCode = 1;
}DomainWhois.lookUp(domain) queries the IP2WHOIS service. Fields and contact details may be missing or redacted.
final whois = DomainWhois(config);
try {
final result = await whois.lookUp('example.com');
final registrar = result['registrar'];
stdout.writeln('Domain: ${result['domain'] ?? 'N/A'}');
stdout.writeln('Created: ${result['create_date'] ?? 'N/A'}');
stdout.writeln('Expires: ${result['expire_date'] ?? 'N/A'}');
stdout.writeln('Registrar: ${registrar is Map ? (registrar['name'] ?? 'N/A') : 'N/A'}');
} catch (e) {
stderr.writeln('WHOIS lookup failed: $e');
exitCode = 1;
}See the DomainWhois class reference for available fields.
DomainWhois includes synchronous helper methods. These examples do not perform network lookups:
final whois = DomainWhois(config);
stdout.writeln(whois.toPunycode('täst.de'));
stdout.writeln(whois.toNormalText('xn--tst-qla.de'));
stdout.writeln(whois.toDomainName('https://www.example.com/path'));
stdout.writeln(whois.toDomainExtension('example.com'));These method names differ from the PHP SDK (toPunycode, toNormalText, toDomainName and toDomainExtension rather than get...). Handle invalid input appropriately in your application.
The optional second argument to HostedDomain.lookUp(ip, page) is an integer page number; it defaults to page 1.
final hostedDomains = HostedDomain(config);
try {
final result = await hostedDomains.lookUp('8.8.8.8', 1);
stdout.writeln('Total domains: ${result['TotalDomains'] ?? 'N/A'}');
stdout.writeln('Domains: ${result['Domains'] ?? []}');
} catch (e) {
stderr.writeln('Hosted domain lookup failed: $e');
exitCode = 1;
}Pass 2, 3, etc. to request further pages. The Dart API reference documents response keys including Page, PerPage, TotalPages and Domains. Check the returned data before requesting further pages.
- Dart backend localization: Suggest region-appropriate language, content or currency from approximate IP location.
- Traffic analytics and enrichment: Add country, ASN and network attributes to application events.
- Security review: Supplement other risk signals with proxy, VPN, Tor, crawler or fraud indicators where available.
- Domain research: Retrieve registration dates, registrar details and nameservers from WHOIS responses.
- Network and hosting research: Explore autonomous systems, ISPs and domains hosted on IP addresses.
- Dart SDK quickstart and examples
- Dart API reference for all four classes and response fields
- Official GitHub repository
- Dart package on pub.dev
- IP2Location.io API plans and query limits
- IP Geolocation API rate limits and authentication
- Report a Dart SDK bug or request a feature
- API and account support
Licensed under the MIT License. See LICENSE.