lim-qqwry
TypeScript icon, indicating that this package has built-in type declarations

2.1.2 • Public • Published

lim-qqwry

lim-qqwry

A module for CZIP address library qqwry.dat, which can perform isp query and convert .dat files into json files, which can be directly imported into MongoDB, etc.


Installation

LimQqwry requires Node.js v6.0.0 or higher for ES2015 and async function support.

npm install lim-qqwry

Example

import LimQqwry from "lim-qqwry";
import path from "path";
import fs from "fs";

const datapath = path.join(__dirname, "./qqwry.dat");
const qqwry = new LimQqwry(datapath);
// query ip information
const ipdata = qqwry.searchIP("115.120.105.66");
console.log(ipdata);
// convert to json
const result = qqwry.toJson(datapath);
fs.writeFile("./data.json", JSON.stringify(result), () => {
  console.log("succeed!");
});

Note that when creating a new instance, the module will read the .dat file into the memory to improve the speed of subsequent operations (extreme speed mode in the original code), so if it is a one-time conversion instead of query services, please pay attention to the memory overflow problem.


Other

Used with MongoDB, you can store StartIpIntList instead of qqwry.dat in memory all the time, get queryIp through the provided static method, and go to the database to query:

let startIpIntList = null;
async function queryIpInfo(ip) {
  if (!startIpIntList) {
    startIpIntList = new LimQqwry(
      path.join(process.cwd(), "data/qqwry.dat")
    ).getStartIpIntList();
  }
  const ipInt = LimQqwry.ipToInt(ip);
  const queryIp = LimQqwry.getStartIpInt(ipInt, startIpIntList);
  const data = await Mapper.getIpData(queryIp); // database query code example
  return { ip, country: data.country, isp: data.isp };
}

Readme

Keywords

Package Sidebar

Install

npm i lim-qqwry

Weekly Downloads

24

Version

2.1.2

License

MIT

Unpacked Size

15.9 kB

Total Files

6

Last publish

Collaborators

  • limkim