|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.maxmind.geoip.LookupService
public class LookupService
Provides a lookup service for information based on an IP address. The location of a database file is supplied when creating a lookup service instance. The edition of the database determines what information is available about an IP address. See the DatabaseInfo class for further details.
The following code snippet demonstrates looking up the country that an IP address is from:
// First, create a LookupService instance with the location of the database. LookupService lookupService = new LookupService("c:\\geoip.dat"); // Assume we have a String ipAddress (in dot-decimal form). Country country = lookupService.getCountry(ipAddress); System.out.println("The country is: " + country.getName()); System.out.println("The country code is: " + country.getCode());In general, a single LookupService instance should be created and then reused repeatedly.
Tip: Those deploying the GeoIP API as part of a web application may find it difficult to pass in a File to create the lookup service, as the location of the database may vary per deployment or may even be part of the web-application. In this case, the database should be added to the classpath of the web-app. For example, by putting it into the WEB-INF/classes directory of the web application. The following code snippet demonstrates how to create a LookupService using a database that can be found on the classpath:
String fileName = getClass().getResource("/GeoIP.dat").toExternalForm().substring(6); LookupService lookupService = new LookupService(fileName);
Field Summary | |
---|---|
static int |
GEOIP_CABLEDSL_SPEED
|
static int |
GEOIP_CHECK_CACHE
|
static int |
GEOIP_CORPORATE_SPEED
|
static int |
GEOIP_DIALUP_SPEED
|
static int |
GEOIP_INDEX_CACHE
|
static int |
GEOIP_MEMORY_CACHE
|
static int |
GEOIP_STANDARD
|
static int |
GEOIP_UNKNOWN_SPEED
|
Constructor Summary | |
---|---|
LookupService(java.io.File databaseFile)
Create a new lookup service using the specified database file. |
|
LookupService(java.io.File databaseFile,
int options)
Create a new lookup service using the specified database file. |
|
LookupService(java.io.File databaseFile,
java.lang.String licenseKey)
Create a new distributed lookup service using the license key |
|
LookupService(int options,
java.lang.String licenseKey)
Create a new distributed lookup service using the license key |
|
LookupService(java.lang.String databaseFile)
Create a new lookup service using the specified database file. |
|
LookupService(java.lang.String databaseFile,
int options)
Create a new lookup service using the specified database file. |
|
LookupService(java.lang.String databaseFile,
java.lang.String licenseKey)
Create a new distributed lookup service using the license key |
Method Summary | |
---|---|
void |
close()
Closes the lookup service. |
Country |
getCountry(java.net.InetAddress ipAddress)
Returns the country the IP address is in. |
Country |
getCountry(long ipAddress)
Returns the country the IP address is in. |
Country |
getCountry(java.lang.String ipAddress)
Returns the country the IP address is in. |
Country |
getCountryV6(java.net.InetAddress addr)
Returns the country the IP address is in. |
Country |
getCountryV6(java.lang.String ipAddress)
Returns the country the IP address is in. |
DatabaseInfo |
getDatabaseInfo()
Returns information about the database. |
int |
getID(java.net.InetAddress ipAddress)
|
int |
getID(long ipAddress)
|
int |
getID(java.lang.String ipAddress)
|
Location |
getLocation(java.net.InetAddress addr)
|
Location |
getLocation(long ipnum)
|
Location |
getLocation(java.lang.String str)
|
Location |
getLocationV6(java.net.InetAddress addr)
|
Location |
getLocationV6(java.lang.String str)
|
Location |
getLocationwithdnsservice(java.lang.String str)
|
java.lang.String |
getOrg(java.net.InetAddress addr)
|
java.lang.String |
getOrg(long ipnum)
|
java.lang.String |
getOrg(java.lang.String str)
|
java.lang.String |
getOrgV6(java.net.InetAddress addr)
|
java.lang.String |
getOrgV6(java.lang.String str)
|
Region |
getRegion(long ipnum)
|
Region |
getRegion(java.lang.String str)
|
int |
last_netmask()
|
void |
netmask(int nm)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int GEOIP_STANDARD
public static final int GEOIP_MEMORY_CACHE
public static final int GEOIP_CHECK_CACHE
public static final int GEOIP_INDEX_CACHE
public static final int GEOIP_UNKNOWN_SPEED
public static final int GEOIP_DIALUP_SPEED
public static final int GEOIP_CABLEDSL_SPEED
public static final int GEOIP_CORPORATE_SPEED
Constructor Detail |
---|
public LookupService(java.lang.String databaseFile, java.lang.String licenseKey) throws java.io.IOException
databaseFile
- String representation of the database file.licenseKey
- license key provided by Maxmind to access distributed service
java.io.IOException
public LookupService(java.io.File databaseFile, java.lang.String licenseKey) throws java.io.IOException
databaseFile
- the database file.licenseKey
- license key provided by Maxmind to access distributed service
java.io.IOException
public LookupService(int options, java.lang.String licenseKey) throws java.io.IOException
options
- Resevered for future uselicenseKey
- license key provided by Maxmind to access distributed service
java.io.IOException
public LookupService(java.lang.String databaseFile) throws java.io.IOException
databaseFile
- String representation of the database file.
java.io.IOException
- if an error occured creating the lookup service
from the database file.public LookupService(java.io.File databaseFile) throws java.io.IOException
databaseFile
- the database file.
java.io.IOException
- if an error occured creating the lookup service
from the database file.public LookupService(java.lang.String databaseFile, int options) throws java.io.IOException
databaseFile
- String representation of the database file.options
- database flags to use when opening the database
GEOIP_STANDARD read database from disk
GEOIP_MEMORY_CACHE cache the database in RAM and read it from RAM
java.io.IOException
- if an error occured creating the lookup service
from the database file.public LookupService(java.io.File databaseFile, int options) throws java.io.IOException
databaseFile
- the database file.options
- database flags to use when opening the database
GEOIP_STANDARD read database from disk
GEOIP_MEMORY_CACHE cache the database in RAM and read it from RAM
java.io.IOException
- if an error occured creating the lookup service
from the database file.Method Detail |
---|
public void close()
public Country getCountryV6(java.lang.String ipAddress)
ipAddress
- String version of an IPv6 address, i.e. "::127.0.0.1"
public Country getCountry(java.lang.String ipAddress)
ipAddress
- String version of an IP address, i.e. "127.0.0.1"
public Country getCountry(java.net.InetAddress ipAddress)
ipAddress
- the IP address.
public Country getCountryV6(java.net.InetAddress addr)
addr
- the IP address as Inet6Address.
public Country getCountry(long ipAddress)
ipAddress
- the IP address in long format.
public int getID(java.lang.String ipAddress)
public int getID(java.net.InetAddress ipAddress)
public int getID(long ipAddress)
public int last_netmask()
public void netmask(int nm)
public DatabaseInfo getDatabaseInfo()
public Location getLocationV6(java.lang.String str)
public Location getLocation(java.net.InetAddress addr)
public Location getLocation(java.lang.String str)
public Location getLocationwithdnsservice(java.lang.String str)
public Region getRegion(java.lang.String str)
public Region getRegion(long ipnum)
public Location getLocationV6(java.net.InetAddress addr)
public Location getLocation(long ipnum)
public java.lang.String getOrg(java.net.InetAddress addr)
public java.lang.String getOrg(java.lang.String str)
public java.lang.String getOrg(long ipnum)
public java.lang.String getOrgV6(java.lang.String str)
public java.lang.String getOrgV6(java.net.InetAddress addr)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |