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
This extension does not provide ip2region.xdb file, please download it from ip2region.xdb here. How to update also refer to this library readme.
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;
}
}
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;
}
}
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;
}
}
dart run example/main.dart
#{region: 美国|0|0|0|Level3, ioCount: 8, took: 2392}