ip2location-io-d ~main

IP2Location.io D Library


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

IP2Location.io D SDK

This D libary enables user to query for an enriched data set, such as country, region, district, city, latitude & longitude, ZIP code, time zone, ASN, ISP, domain, net speed, IDD code, area code, weather station data, MNC, MCC, mobile brand, elevation, usage type, address type, advertisement category and proxy data with an IP address. It supports both IPv4 and IPv6 address lookup.

In addition, this library provides WHOIS lookup api that helps users to obtain domain information, WHOIS record, by using a domain name. The WHOIS API returns a comprehensive WHOIS data such as creation date, updated date, expiration date, domain age, the contact information of the registrant, mailing address, phone number, email address, nameservers the domain is using and much more.

This library requires API key to function. You may sign up for a free API key at https://www.ip2location.io/pricing.

Installation using dub

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

Usage Example

Lookup IP Address Geolocation Data

import std.stdio;
import ipgeolocation;
import configuration;

int main() {
	// Query for IP geolocation
	auto ip = "8.8.8.8";
	auto apiKey = "YOUR_API_KEY";
	auto lang = "es";
	
	auto conf = new Configuration(apiKey);
	
	auto ipl = new IPGeolocation(conf);
	
	auto result = ipl.lookup(ip, lang); // lang param only supported by Plus and Security plans, so omit if not needed
	
	if ("country_code" in result) {
		writefln("ip: %s", ("ip" in result) ? result["ip"].str : "");
		writefln("country_code: %s", ("country_code" in result) ? result["country_code"].str : "");
		writefln("country_name: %s", ("country_name" in result) ? result["country_name"].str : "");
		writefln("region_name: %s", ("region_name" in result) ? result["region_name"].str : "");
		writefln("city_name: %s", ("city_name" in result) ? result["city_name"].str : "");
		writefln("latitude: %f", ("latitude" in result) ? result["latitude"].floating : 0.0);
		writefln("longitude: %f", ("longitude" in result) ? result["longitude"].floating : 0.0);
		writefln("zip_code: %s", ("zip_code" in result) ? result["zip_code"].str : "");
		writefln("time_zone: %s", ("time_zone" in result) ? result["time_zone"].str : "");
		writefln("asn: %s", ("asn" in result) ? result["asn"].str : "");
		writefln("as: %s", ("as" in result) ? result["as"].str : "");
		writefln("isp: %s", ("isp" in result) ? result["isp"].str : "");
		writefln("domain: %s", ("domain" in result) ? result["domain"].str : "");
		writefln("net_speed: %s", ("net_speed" in result) ? result["net_speed"].str : "");
		writefln("idd_code: %s", ("idd_code" in result) ? result["idd_code"].str : "");
		writefln("area_code: %s", ("area_code" in result) ? result["area_code"].str : "");
		writefln("weather_station_code: %s", ("weather_station_code" in result) ? result["weather_station_code"].str : "");
		writefln("weather_station_name: %s", ("weather_station_name" in result) ? result["weather_station_name"].str : "");
		writefln("mcc: %s", ("mcc" in result) ? result["mcc"].str : "");
		writefln("mnc: %s", ("mnc" in result) ? result["mnc"].str : "");
		writefln("mobile_brand: %s", ("mobile_brand" in result) ? result["mobile_brand"].str : "");
		writefln("elevation: %d", ("elevation" in result) ? result["elevation"].integer : 0);
		writefln("usage_type: %s", ("usage_type" in result) ? result["usage_type"].str : "");
		writefln("address_type: %s", ("address_type" in result) ? result["address_type"].str : "");
		writefln("district: %s", ("district" in result) ? result["district"].str : "");
		writefln("ads_category: %s", ("ads_category" in result) ? result["ads_category"].str : "");
		writefln("ads_category_name: %s", ("ads_category_name" in result) ? result["ads_category_name"].str : "");
		writefln("is_proxy: %s", ("is_proxy" in result) ? result["is_proxy"].boolean : false);
		
		// continent addon
		if ("continent" in result) {
			auto continent = result["continent"];
			writefln("continent => name: %s", continent["name"].str);
			writefln("continent => code: %s", continent["code"].str);
			writefln("continent => hemisphere: %s", continent["hemisphere"]);
			writefln("continent => translation: %s", continent["translation"]);
		}
		
		// country addon
		if ("country" in result) {
			auto country = result["country"];
			writefln("country => name: %s", country["name"].str);
			writefln("country => alpha3_code: %s", country["alpha3_code"].str);
			writefln("country => numeric_code: %s", country["numeric_code"].integer);
			writefln("country => demonym: %s", country["demonym"].str);
			writefln("country => flag: %s", country["flag"].str);
			writefln("country => capital: %s", country["capital"].str);
			writefln("country => total_area: %s", country["total_area"].integer);
			writefln("country => population: %s", country["population"].integer);
			writefln("country => tld: %s", country["tld"].str);
			writefln("country => translation: %s", country["translation"]);
			
			writefln("country => currency => code: %s", country["currency"]["code"].str);
			writefln("country => currency => name: %s", country["currency"]["name"].str);
			writefln("country => currency => symbol: %s", country["currency"]["symbol"].str);
			
			writefln("country => language => code: %s", country["language"]["code"].str);
			writefln("country => language => name: %s", country["language"]["name"].str);
		}
		
		// region addon
		if ("region" in result) {
			auto region = result["region"];
			writefln("region => name: %s", region["name"].str);
			writefln("region => code: %s", region["code"].str);
			writefln("region => translation: %s", region["translation"]);
		}
		
		// city addon
		if ("city" in result) {
			auto city = result["city"];
			writefln("city => name: %s", city["name"].str);
			writefln("city => translation: %s", city["translation"]);
		}
		
		// time_zone_info addon
		if ("time_zone_info" in result) {
			auto timezone = result["time_zone_info"];
			writefln("time_zone_info => olson: %s", timezone["olson"].str);
			writefln("time_zone_info => current_time: %s", timezone["current_time"].str);
			writefln("time_zone_info => gmt_offset: %d", timezone["gmt_offset"].integer);
			writefln("time_zone_info => is_dst: %s", timezone["is_dst"].boolean);
			writefln("time_zone_info => sunrise: %s", timezone["sunrise"].str);
			writefln("time_zone_info => sunset: %s", timezone["sunset"].str);
		}
		
		// geotargeting addon
		if ("geotargeting" in result) {
			writefln("geotargeting => metro: %s", result["geotargeting"]["metro"].str);
		}
		
		// proxy addon
		if ("proxy" in result) {
			auto proxy = result["proxy"];
			writefln("proxy => last_seen: %d", proxy["last_seen"].integer);
			writefln("proxy => proxy_type: %s", proxy["proxy_type"].str);
			writefln("proxy => threat: %s", proxy["threat"].str);
			writefln("proxy => provider: %s", proxy["provider"].str);
			writefln("proxy => is_vpn: %s", proxy["is_vpn"].boolean);
			writefln("proxy => is_tor: %s", proxy["is_tor"].boolean);
			writefln("proxy => is_data_center: %s", proxy["is_data_center"].boolean);
			writefln("proxy => is_public_proxy: %s", proxy["is_public_proxy"].boolean);
			writefln("proxy => is_web_proxy: %s", proxy["is_web_proxy"].boolean);
			writefln("proxy => is_web_crawler: %s", proxy["is_web_crawler"].boolean);
			writefln("proxy => is_residential_proxy: %s", proxy["is_residential_proxy"].boolean);
			writefln("proxy => is_spammer: %s", proxy["is_spammer"].boolean);
			writefln("proxy => is_scanner: %s", proxy["is_scanner"].boolean);
			writefln("proxy => is_botnet: %s", proxy["is_botnet"].boolean);
		}
	}
	else if ("error" in result) {
		writefln("Error: %s", result["error"]["error_message"]);
	}
	else {
		writeln("Error: Unknown error.");
	}
	
	return 0;
}

Lookup Domain Information

import std.stdio;
import domainwhois;
import configuration;

int main() {
	auto apiKey = "YOUR_API_KEY";
	auto conf = new Configuration(apiKey);
	auto domain = "locaproxy.com";
	auto whois = new DomainWhois(conf);
	
	auto result = whois.lookup(domain);
	
	if ("domain" in result) {
		writefln("domain: %s", result["domain"].str);
		writefln("domain_id: %s", result["domain_id"].str);
		writefln("status: %s", result["status"].str);
		writefln("create_date: %s", result["create_date"].str);
		writefln("update_date: %s", result["update_date"].str);
		writefln("expire_date: %s", result["expire_date"].str);
		writefln("domain_age: %s", result["domain_age"].integer);
		writefln("whois_server: %s", result["whois_server"].str);
		writefln("nameservers: %s", result["nameservers"]);
		
		auto registrar = result["registrar"];
		writefln("registrar => iana_id: %s", registrar["iana_id"].str);
		writefln("registrar => name: %s", registrar["name"].str);
		writefln("registrar => url: %s", registrar["url"].str);
		
		auto registrant = result["registrant"];
		writefln("registrant => name: %s", registrant["name"].str);
		writefln("registrant => organization: %s", registrant["organization"].str);
		writefln("registrant => street_address: %s", registrant["street_address"].str);
		writefln("registrant => city: %s", registrant["city"].str);
		writefln("registrant => region: %s", registrant["region"].str);
		writefln("registrant => zip_code: %s", registrant["zip_code"].str);
		writefln("registrant => country: %s", registrant["country"].str);
		writefln("registrant => phone: %s", registrant["phone"].str);
		writefln("registrant => fax: %s", registrant["fax"].str);
		writefln("registrant => email: %s", registrant["email"].str);
		
		auto admin = result["admin"];
		writefln("admin => name: %s", admin["name"].str);
		writefln("admin => organization: %s", admin["organization"].str);
		writefln("admin => street_address: %s", admin["street_address"].str);
		writefln("admin => city: %s", admin["city"].str);
		writefln("admin => region: %s", admin["region"].str);
		writefln("admin => zip_code: %s", admin["zip_code"].str);
		writefln("admin => country: %s", admin["country"].str);
		writefln("admin => phone: %s", admin["phone"].str);
		writefln("admin => fax: %s", admin["fax"].str);
		writefln("admin => email: %s", admin["email"].str);
		
		auto tech = result["tech"];
		writefln("tech => name: %s", tech["name"].str);
		writefln("tech => organization: %s", tech["organization"].str);
		writefln("tech => street_address: %s", tech["street_address"].str);
		writefln("tech => city: %s", tech["city"].str);
		writefln("tech => region: %s", tech["region"].str);
		writefln("tech => zip_code: %s", tech["zip_code"].str);
		writefln("tech => country: %s", tech["country"].str);
		writefln("tech => phone: %s", tech["phone"].str);
		writefln("tech => fax: %s", tech["fax"].str);
		writefln("tech => email: %s", tech["email"].str);
		
		auto billing = result["billing"];
		writefln("billing => name: %s", billing["name"].str);
		writefln("billing => organization: %s", billing["organization"].str);
		writefln("billing => street_address: %s", billing["street_address"].str);
		writefln("billing => city: %s", billing["city"].str);
		writefln("billing => region: %s", billing["region"].str);
		writefln("billing => zip_code: %s", billing["zip_code"].str);
		writefln("billing => country: %s", billing["country"].str);
		writefln("billing => phone: %s", billing["phone"].str);
		writefln("billing => fax: %s", billing["fax"].str);
		writefln("billing => email: %s", billing["email"].str);
	}
	else if ("error" in result) {
		writefln("Error: %s", result["error"]["error_message"]);
	}
	else {
		writeln("Error: Unknown error.");
	}
	
	return 0;
}

Convert Normal Text to Punycode

import std.stdio;
import domainwhois;
import configuration;

int main() {
	auto conf = new Configuration("");
	auto whois = new DomainWhois(conf);
	writefln("Punycode: %s", whois.getPunycode("täst.de"));
	return 0;
}

Convert Punycode to Normal Text

import std.stdio;
import domainwhois;
import configuration;

int main() {
	auto conf = new Configuration("");
	auto whois = new DomainWhois(conf);
	writefln("NormalText: %s", whois.getNormalText("xn--tst-qla.de"));
	return 0;
}

Get Domain Name

import std.stdio;
import domainwhois;
import configuration;

int main() {
	auto conf = new Configuration("");
	auto whois = new DomainWhois(conf);
	writefln("DomainName: %s", whois.getDomainName("https://www.example.com/exe"));
	return 0;
}

Get Domain Extension

import std.stdio;
import domainwhois;
import configuration;

int main() {
	auto conf = new Configuration("");
	auto whois = new DomainWhois(conf);
	writefln("DomainExtension: %s", whois.getDomainExtension("example.com"));
	
	return 0;
}

Response Parameter

IP Geolocation Lookup function

ParameterTypeDescription
ipstringIP address.
country_codestringTwo-character country code based on ISO 3166.
country_namestringCountry name based on ISO 3166.
region_namestringRegion or state name.
city_namestringCity name.
latitudedoubleCity latitude. Defaults to capital city latitude if city is unknown.
longitudedoubleCity longitude. Defaults to capital city longitude if city is unknown.
zip_codestringZIP/Postal code.
time_zonestringUTC time zone (with DST supported).
asnstringAutonomous system number (ASN).
asstringAutonomous system (AS) name.
ispstringInternet Service Provider or company's name.
domainstringInternet domain name associated with IP address range.
net_speedstringInternet connection type. DIAL = dial-up, DSL = broadband/cable/fiber/mobile, COMP = company/T1
idd_codestringThe IDD prefix to call the city from another country.
area_codestringA varying length number assigned to geographic areas for calls between cities.
weatherstationcodestringThe special code to identify the nearest weather observation station.
weatherstationnamestringThe name of the nearest weather observation station.
mccstringMobile Country Codes (MCC) as defined in ITU E.212 for use in identifying mobile stations in wireless telephone networks, particularly GSM and UMTS networks.
mncstringMobile Network Code (MNC) is used in combination with a Mobile Country Code (MCC) to uniquely identify a mobile phone operator or carrier.
mobile_brandstringCommercial brand associated with the mobile carrier.
elevationintegerAverage height of city above sea level in meters (m).
usage_typestringUsage type classification of ISP or company.
address_typestringIP address types as defined in Internet Protocol version 4 (IPv4) and Internet Protocol version 6 (IPv6).
continent.namestringContinent name.
continent.codestringTwo-character continent code.
continent.hemispherearrayThe hemisphere of where the country located. The data in array format with first item indicates (north/south) hemisphere and second item indicates (east/west) hemisphere information.
continent.translationobjectTranslation data based on the given lang code.
districtstringDistrict or county name.
country.namestringCountry name based on ISO 3166.
country.alpha3_codestringThree-character country code based on ISO 3166.
country.numeric_codestringThree-character country numeric code based on ISO 3166.
country.demonymstringNative of the country.
country.flagstringURL of the country flag image.
country.capitalstringCapital of the country.
country.total_areaintegerTotal area in km2.
country.populationintegerPopulation of the country.
country.currencyobjectCurrency of the country.
country.languageobjectLanguage of the country.
country.tldstringCountry-Code Top-Level Domain.
country.translationobjectTranslation data based on the given lang code.
region.namestringRegion or state name.
region.codestringISO3166-2 code.
region.translationobjectTranslation data based on the given lang code.
city.namestringCity name.
city.translationobjectTranslation data based on the given lang code.
timezoneinfo.olsonstringTime zone in Olson format.
timezoneinfo.current_timestringCurrent time in ISO 8601 format.
timezoneinfo.gmt_offsetintegerGMT offset value in seconds.
timezoneinfo.is_dstbooleanIndicate if the time zone value is in DST.
timezoneinfo.sunrisestringTime of sunrise. (hh:mm format in local time, i.e, 07:47)
timezoneinfo.sunsetstringTime of sunset. (hh:mm format in local time, i.e 19:50)
geotargeting.metrostringMetro code based on zip/postal code.
ads_categorystringThe domain category code based on IAB Tech Lab Content Taxonomy.
adscategorynamestringThe domain category based on IAB Tech Lab Content Taxonomy. These categories are comprised of Tier-1 and Tier-2 (if available) level categories widely used in services like advertising, Internet security and filtering appliances.
is_proxybooleanWhether is a proxy or not.
proxy.last_seenintegerProxy last seen in days.
proxy.proxy_typestringType of proxy.
proxy.threatstringSecurity threat reported.
proxy.providerstringName of VPN provider if available.
proxy.is_vpnbooleanAnonymizing VPN services.
proxy.is_torbooleanTor Exit Nodes.
proxy.isdatacenterbooleanHosting Provider, Data Center or Content Delivery Network.
proxy.ispublicproxybooleanPublic Proxies.
proxy.iswebproxybooleanWeb Proxies.
proxy.iswebcrawlerbooleanSearch Engine Robots.
proxy.isresidentialproxybooleanResidential proxies.
proxy.is_spammerbooleanEmail and forum spammers.
proxy.is_scannerbooleanNetwork security scanners.
proxy.is_botnetbooleanMalware infected devices.
{
  "ip": "8.8.8.8",
  "country_code": "US",
  "country_name": "United States of America",
  "region_name": "California",
  "city_name": "Mountain View",
  "latitude": 37.405992,
  "longitude": -122.078515,
  "zip_code": "94043",
  "time_zone": "-07:00",
  "asn": "15169",
  "as": "Google LLC",
  "isp": "Google LLC",
  "domain": "google.com",
  "net_speed": "T1",
  "idd_code": "1",
  "area_code": "650",
  "weather_station_code": "USCA0746",
  "weather_station_name": "Mountain View",
  "mcc": "-",
  "mnc": "-",
  "mobile_brand": "-",
  "elevation": 32,
  "usage_type": "DCH",
  "address_type": "Anycast",
  "continent": {
    "name": "North America",
    "code": "NA",
    "hemisphere": [
      "north",
      "west"
    ],
    "translation": {
      "lang": "es",
      "value": "Norteamérica"
    }
  },
  "district": "Santa Clara County",
  "country": {
    "name": "United States of America",
    "alpha3_code": "USA",
    "numeric_code": 840,
    "demonym": "Americans",
    "flag": "https://cdn.ip2location.io/assets/img/flags/us.png",
    "capital": "Washington, D.C.",
    "total_area": 9826675,
    "population": 331002651,
    "currency": {
      "code": "USD",
      "name": "United States Dollar",
      "symbol": "$"
    },
    "language": {
      "code": "EN",
      "name": "English"
    },
    "tld": "us",
    "translation": {
      "lang": "es",
      "value": "Estados Unidos de América (los)"
    }
  },
  "region": {
    "name": "California",
    "code": "US-CA",
    "translation": {
      "lang": "es",
      "value": "California"
    }
  },
  "city": {
    "name": "Mountain View",
    "translation": {
      "lang": null,
      "value": null
    }
  },
  "time_zone_info": {
    "olson": "America/Los_Angeles",
    "current_time": "2023-09-03T18:21:13-07:00",
    "gmt_offset": -25200,
    "is_dst": true,
    "sunrise": "06:41",
    "sunset": "19:33"
  },
  "geotargeting": {
    "metro": "807"
  },
  "ads_category": "IAB19-11",
  "ads_category_name": "Data Centers",
  "is_proxy": false,
  "proxy": {
    "last_seen": 3,
    "proxy_type": "DCH",
    "threat": "-",
    "provider": "-",
    "is_vpn": false,
    "is_tor": false,
    "is_data_center": true,
    "is_public_proxy": false,
    "is_web_proxy": false,
    "is_web_crawler": false,
    "is_residential_proxy": false,
    "is_spammer": false,
    "is_scanner": false,
    "is_botnet": false
  }
}

Domain WHOIS Lookup function

ParameterTypeDescription
domainstringDomain name.
domain_idstringDomain name ID.
statusstringDomain name status.
create_datestringDomain name creation date.
update_datestringDomain name updated date.
expire_datestringDomain name expiration date.
domain_ageintegerDomain name age in day(s).
whois_serverstringWHOIS server name.
registrar.iana_idstringRegistrar IANA ID.
registrar.namestringRegistrar name.
registrar.urlstringRegistrar URL.
registrant.namestringRegistrant name.
registrant.organizationstringRegistrant organization.
registrant.street_addressstringRegistrant street address.
registrant.citystringRegistrant city.
registrant.regionstringRegistrant region.
registrant.zip_codestringRegistrant ZIP Code.
registrant.countrystringRegistrant country.
registrant.phonestringRegistrant phone number.
registrant.faxstringRegistrant fax number.
registrant.emailstringRegistrant email address.
admin.namestringAdmin name.
admin.organizationstringAdmin organization.
admin.street_addressstringAdmin street address.
admin.citystringAdmin city.
admin.regionstringAdmin region.
admin.zip_codestringAdmin ZIP Code.
admin.countrystringAdmin country.
admin.phonestringAdmin phone number.
admin.faxstringAdmin fax number.
admin.emailstringAdmin email address.
tech.namestringTech name.
tech.organizationstringTech organization.
tech.street_addressstringTech street address.
tech.citystringTech city.
tech.regionstringTech region.
tech.zip_codestringTech ZIP Code.
tech.countrystringTech country.
tech.phonestringTech phone number.
tech.faxstringTech fax number.
tech.emailstringTech email address.
billing.namestringBilling name.
billing.organizationstringBilling organization.
billing.street_addressstringBilling street address.
billing.citystringBilling city.
billing.regionstringBilling region.
billing.zip_codestringBilling ZIP Code.
billing.countrystringBilling country.
billing.phonestringBilling phone number.
billing.faxstringBilling fax number.
billing.emailstringBilling email address.
nameserversarrayName servers
{
    "domain": "locaproxy.com",
    "domain_id": "1710914405_DOMAIN_COM-VRSN",
    "status": "clientTransferProhibited https://icann.org/epp#clientTransferProhibited",
    "create_date": "2012-04-03T02:34:32Z",
    "update_date": "2021-12-03T02:54:57Z",
    "expire_date": "2024-04-03T02:34:32Z",
    "domain_age": 3863,
    "whois_server": "whois.godaddy.com",
    "registrar": {
        "iana_id": "146",
        "name": "GoDaddy.com, LLC",
        "url": "https://www.godaddy.com"
    },
    "registrant": {
        "name": "Registration Private",
        "organization": "Domains By Proxy, LLC",
        "street_address": "DomainsByProxy.com",
        "city": "Tempe",
        "region": "Arizona",
        "zip_code": "85284",
        "country": "US",
        "phone": "+1.4806242599",
        "fax": "+1.4806242598",
        "email": "Select Contact Domain Holder link at https://www.godaddy.com/whois/results.aspx?domain=LOCAPROXY.COM"
    },
    "admin": {
        "name": "Registration Private",
        "organization": "Domains By Proxy, LLC",
        "street_address": "DomainsByProxy.com",
        "city": "Tempe",
        "region": "Arizona",
        "zip_code": "85284",
        "country": "US",
        "phone": "+1.4806242599",
        "fax": "+1.4806242598",
        "email": "Select Contact Domain Holder link at https://www.godaddy.com/whois/results.aspx?domain=LOCAPROXY.COM"
    },
    "tech": {
        "name": "Registration Private",
        "organization": "Domains By Proxy, LLC",
        "street_address": "DomainsByProxy.com",
        "city": "Tempe",
        "region": "Arizona",
        "zip_code": "85284",
        "country": "US",
        "phone": "+1.4806242599",
        "fax": "+1.4806242598",
        "email": "Select Contact Domain Holder link at https://www.godaddy.com/whois/results.aspx?domain=LOCAPROXY.COM"
    },
    "billing": {
        "name": "",
        "organization": "",
        "street_address": "",
        "city": "",
        "region": "",
        "zip_code": "",
        "country": "",
        "phone": "",
        "fax": "",
        "email": ""
    },
    "nameservers": ["vera.ns.cloudflare.com", "walt.ns.cloudflare.com"]
}

LICENCE

See the LICENSE file.

Authors:
  • IP2Location
Dependencies:
urld
Versions:
1.0.0 2023-Sep-06
~main 2023-Sep-06
Show all 2 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 2 downloads this month

  • 2 downloads total

Score:
0.5
Short URL:
ip2location-io-d.dub.pm