Offline query IP query latitude and longitude, country code, and other information

Source: Internet
Author: User
Tags geoip

    1. GeoIP Introduction

    2. Resources

    3. Code

    4. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.