Skip to content

ip2region_plus - is a dart language implementation. It can be used in dart or flutter。

License

Notifications You must be signed in to change notification settings

biner88/ip2region_plus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pub package

Ip2region_plus

ip2region_plus - is a dart language implementation. It can be used in dart or flutter。

ip2region - is a offline IP address location library and IP location data management framework, 10 microsecond level query efficiency, provides a variety of mainstream programming language xdb data generation and query client implementation. Other language versions please see lionsoul2014/ip2region

English | 中文

Install

This extension does not provide ip2region.xdb file, please download it from ip2region.xdb here. How to update also refer to this library readme.

Useage

File-based querying

import 'package:ip2region_plus/ip2region_plus.dart';

void main() {
  String dbFile = "ip2region.xdb";
  IP2RegionPlus searcher;
  try {
    searcher = IP2RegionPlus.newWithFileOnly(dbFile);
    Map region = searcher.search('8.8.8.8');
    print(region);
  } catch (e) {
    print("failed to create searcher with '$dbFile': $e");
    return;
  }
}

Cache VectorIndex index

import 'package:ip2region_plus/ip2region_plus.dart';

void main() {
  String dbFile = "ip2region.xdb";
  IP2RegionPlus searcher;
  try {
    var vIndex = IP2RegionPlus.loadVectorIndexFromFile(dbFile);
    searcher = IP2RegionPlus.newWithVectorIndex(dbFile, vIndex);
    Map region = searcher.search('8.8.8.132');
    print(region);
  } catch (e) {
    print("failed to create searcher with '$dbFile': $e");
    return;
  }
}

Cache the entire xdb data

import 'package:ip2region_plus/ip2region_plus.dart';

void main() {
  String dbFile = "ip2region.xdb";
  IP2RegionPlus searcher;
  var cBuff = IP2RegionPlus.loadContentFromFile(dbFile);
  if (cBuff == null) {
    print("failed to load content buffer from $dbFile");
    return;
  }
  try {
    searcher = IP2RegionPlus.newWithBuffer(cBuff);
    Map region = searcher.search('8.8.8.132');
    print(region);
  } catch (e) {
    print(e);
    return;
  }
}

Example

dart run example/main.dart
#{region: 美国|0|0|0|Level3, ioCount: 8, took: 2392}

About

ip2region_plus - is a dart language implementation. It can be used in dart or flutter。

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages