GeoIP Introduction
Resources
Code
Debug and Success
I. Introduction of GEOIP
geolocation IP, based on the geographical location of IP query, Enterprise website (open can link), we can according to the free version of the GeoIP dat offline IP data file to query.
Ii. Resources
IP Offline Files (unzip and put to C drive) download the project's required jar package: 1 2
Third, the code
package com.arcsight.service;import com.maxmind.geoip.lookupservice;import java.io.ioexception; IMPORT JAVA.NET.INETADDRESS;/** * CREATED BY SHAOYONGYANG ON 2015/7/6. */public class ipsearchservice { public static void main (String [] args) { try { //InetAddress ip = Inetaddress.getbyaddress ("218.28.2.111". GetBytes ());    //SYSTEM.OUT.PRINTLN (IP); string sep = system.getproperty ("File.separator"); String dir = "c://"; //geolitecity.dat in the root directory of the C-drive String dbfile = dir + sep + "GeoLiteCity.dat"; lookupservice cl = new lookupservice (DBFile, Lookupservice.geoip_memory_cache); // System.out.println (Cl.getcountry ("218.28.2.111"). GetName ()); inetaddress inetaddress = inetaddress.getbyname ("218.28.2.111"); //system.out.println (Cl.getLocation ( inetaddress)); system.out.println ( Cl.getlocation (inetaddress). CountryCode); system.out.println (Cl.getlocation (inetaddress). Area_code); system.out.println ( Cl.getlocation (inetaddress); System.out.println (Cl.getlocation (inetaddress). Region); system.out.println (Cl.getlocation (inetaddress) dma_code); system.out.println (Cl.getlocation ("218.28.2.111"). Latitude); system.out.println (Cl.getLocation (" 218.28.2.111 "). longitude); cl.close (); } catch ( Ioexception e) { E.printstacktrace (); system.out.println ("Io exception"); } }}
The above code has nothing to say but to get a location object.
Iv. Commissioning and Success
No picture-word dick? No picture words dick!!!
Summary: There is no technical content, nothing more than a jar package, Javaer features.
Offline query IP query latitude and longitude, country code, and other information