Ip2Region have Chinese data structures and support, it is a very good third-party ip conversion tool.
java:
<dependency> <groupId>org.lionsoul</groupId> <artifactId>ip2region</artifactId> <version>1.7</version> </dependency>
org.lionsoul.ip2region.DataBlock Import;
Import org.lionsoul.ip2region.DbConfig;
Import org.lionsoul.ip2region.DbSearcher;
public class Ip2Region {
public static void main (String [] args) throws Exception {
// IP
String IP = "121.33.59.18" ;
// determines whether the IP address (available) // = Boolean isIpAddress Util.isIpAddress (IP);
// IP system conversion and long (available) // long ipLong = Util.ip2long (IP); String strIp Util.long2ip = // (ipLong);
// The location information searching IP DBConfig config = new new DBConfig ();
// ip library acquires the position (placed under the src) (direct access by the test class file Ip2RegionTest test category) String dbfile = Ip2Region.class.getResource ( "/ ip2region.db") .getPath (); // Get ip2region.db address DbSearcher searcher = new file under src / java / resources path DbSearcher (config, dbfile); // use Btree = Block Search the DataBlock searcher.btreeSearch (IP); // Print location information (format: country | region | provinces | cities | operator) System.out .println (block.getRegion ());}}
scala:
<dependency>
<groupId>org.lionsoul</groupId>
<artifactId>ip2region</artifactId>
<version>1.7</version>
</dependency>
import org.junit.Test
import org.lionsoul.ip2region.{DataBlock, DbConfig, DbSearcher}
class IPTest {
/**
* IP -> Region, City
*/
@Test
def ip2Region(): Unit = {
val searcher = new DbSearcher(new DbConfig(), "dataset/ip2region.db")
val region = searcher.btreeSearch("121.33.59.18").getRegion println(region) } }
Address: https: //pan.baidu.com/s/13W7EFg-GiBVkMjNdl-a5RA
Password: 0wi6