Created
August 27, 2014 20:43
-
-
Save shrkw/465455224fcbfc92d8d0 to your computer and use it in GitHub Desktop.
MaxMindが提供しているGeoLite2をScalaから利用してみる ref: http://qiita.com/shrkw/items/3d98dd7e266932feab21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File | |
import java.net.InetAddress | |
import com.maxmind.geoip2.DatabaseReader.Builder | |
import com.maxmind.geoip2.exception.AddressNotFoundException | |
object GeoipSample { | |
def main(args: Array[String]): Unit ={ | |
val database = new File("/tmp/GeoLite2-Country.mmdb") | |
// This creates the DatabaseReader object, which should be reused across lookups. | |
val reader = new Builder(database).build() | |
val ipAddresses = Seq("128.101.101.101", "192.168.100.1", "183.79.135.206", "212.58.244.18") | |
ipAddresses foreach { ip => | |
try { | |
println(reader.country(InetAddress.getByName(ip))) | |
} catch { | |
case e: AddressNotFoundException => println(e) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment