8000 GitHub - ip2location/ip2location-io-dart: Dart wrapper for the IP2Location.io API. Get IPv4/IPv6 geolocation and proxy details, or WHOIS information for a domain. Add IP address intelligence to Dart applications and services. Use a hosted geolocation API to enrich user traffic, analyze network attributes and integrate domain lookup capabilities without building raw HTTP requests. · GitHub
[go: up one dir, main page]

Skip to content

About

Dart wrapper for the IP2Location.io API. Get IPv4/IPv6 geolocation and proxy details, or WHOIS information for a domain. Add IP address intelligence to Dart applications and services. Use a hosted geolocation API to enrich user traffic, analyze network attributes and integrate domain lookup capabilities without building raw HTTP requests.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

Repository files navigation

IP2Location.io Dart SDK — IP Geolocation, Domain WHOIS & Hosted Domain Lookup

pub.dev version pub.dev downloads

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

Features

  • 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>> and async/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.

SDK classes

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.

API access and query limits

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.

Requirements

The package declares http and punycoder as dependencies. Unlike the PHP SDK, no PHP extensions or Composer setup are needed.

Installation

In your Dart project, install the package:

dart pub add ip2location_io

Set 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_KEY

You can also supply it through your environment or deployment configuration. The examples read it with Platform.environment.

Quickstart: IP geolocation lookup

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.dart

Successful 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.

Asynchronous lookups and map responses

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.

More usage examples

Request translated location names

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

Inspect available proxy indicators

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

Look up domain WHOIS information

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.

Use domain and Punycode utilities

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.

Find domains hosted on an IP address

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.

Common use cases

  • 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.

Documentation and support

License

Licensed under the MIT License. See LICENSE.

About

Dart wrapper for the IP2Location.io API. Get IPv4/IPv6 geolocation and proxy details, or WHOIS information for a domain. Add IP address intelligence to Dart applications and services. Use a hosted geolocation API to enrich user traffic, analyze network attributes and integrate domain lookup capabilities without building raw HTTP requests.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

0