Content-Length: 71369 | pFad | http://www.ip2location.com/documentation/ip2location-libraries/scala/get-started#installation

HX IP2Location IP Geolocation Scala Module | IP2Location

Get Started With IP2Location Scala Module

Dependencies

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


IPv4 BIN vs IPv6 BIN

Use the IPv4 BIN file if you just need to query IPv4 addresses.

Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.


Requirements

Intellij IDEA: https://www.jetbrains.com/idea/


Installation

IP2Location Scala: https://central.sonatype.com/artifact/com.ip2location/ip2location-scala_3


Sample Codes

Query geolocation information from BIN database

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

import com.ip2location.IP2Location

@main def testip2location(): Unit = {
 val loc = new IP2Location
 try {
 val ip = "8.8.8.8"
 val binfile = "/usr/data/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY-DISTRICT-ASN.BIN"

 val useMMF = false
 loc.Open(binfile, useMMF) // initialize with BIN file

 val rec = loc.IPQuery(ip)
 if ("OK" == rec.getStatus) System.out.println(rec)
 else if ("EMPTY_IP_ADDRESS" == rec.getStatus) System.out.println("IP address cannot be blank.")
 else if ("INVALID_IP_ADDRESS" == rec.getStatus) System.out.println("Invalid IP address.")
 else if ("MISSING_FILE" == rec.getStatus) System.out.println("Invalid database path.")
 else if ("IPV6_NOT_SUPPORTED" == rec.getStatus) System.out.println("This BIN does not contain IPv6 data.")
 else System.out.println("Unknown error." + rec.getStatus)
 } catch {
 case e: Exception =>
 System.out.println(e)
 e.printStackTrace(System.out)
 } finally loc.Close()
}

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








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://www.ip2location.com/documentation/ip2location-libraries/scala/get-started#installation

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy