2.1.1 • Published 8 months ago

lim-qqwry v2.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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.

Original Code Repository

中文文档

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 };
}

CHANGELOG

2.1.1

8 months ago

2.1.0

8 months ago

2.0.2

11 months ago

2.0.1

1 year ago

2.0.0

1 year ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago