Get Started With IP2Location D Module

Dependencies

This library requires IP2Location BIN database to function. You may download the BIN database at


Installation

To install this library using dub:

"dependencies": {
 "ip2location-d": "~master"
}

Sample Codes

Query geolocation information from BIN database

You can query the geolocation information from the IP2Location BIN database as below:

import std.stdio;
import ip2location : ip2location;

int main() {
 string db = "./IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY-DISTRICT-ASN.BIN";
 ip2location ip2loc = new ip2location(db);
 auto results = ip2loc.get_all("8.8.8.8");

 writeln("country_short: ", results.country_short);
 writeln("country_long: ", results.country_long);
 writeln("region: ", results.region);
 writeln("city: ", results.city);
 writeln("isp: ", results.isp);
 writefln("latitude: %f", results.latitude);
 writefln("longitude: %f", results.longitude);
 writeln("domain: ", results.domain);
 writeln("zipcode: ", results.zipcode);
 writeln("timezone: ", results.timezone);
 writeln("netspeed: ", results.netspeed);
 writeln("iddcode: ", results.iddcode);
 writeln("areacode: ", results.areacode);
 writeln("weatherstationcode: ", results.weatherstationcode);
 writeln("weatherstationname: ", results.weatherstationname);
 writeln("mcc: ", results.mcc);
 writeln("mnc: ", results.mnc);
 writeln("mobilebrand: ", results.mobilebrand);
 writefln("elevation: %f", results.elevation);
 writeln("usagetype: ", results.usagetype);
 writeln("addresstype: ", results.addresstype);
 writeln("category: ", results.category);
 writeln("district: ", results.district);
 writeln("asn: ", results.asn);
 writeln("as: ", results.as);
 writeln("asdomain: ", results.asdomain);
 writeln("asusagetype: ", results.asusagetype);
 writeln("ascidr: ", results.ascidr);

 writeln("API Version: ", ip2loc.api_version());
 ip2loc.close();
 return 0;
}

IP2Location Sample Database (BIN)

The sample BIN files have a limited scope and are only valid for the following IP ranges:

  1. IPv4 : 0.0.0.0 - 7.255.255.255
  2. IPv6 : 2a04:0000:0000:0000:0000:0000:0000:0000 - 2a04:ffff:ffff:ffff:ffff:ffff:ffff:fff