{"id":13834989,"url":"https://github.com/cnwhy/lib-qqwry","last_synced_at":"2025-07-10T07:31:09.363Z","repository":{"id":8864912,"uuid":"10576945","full_name":"cnwhy/lib-qqwry","owner":"cnwhy","description":"用NodeJS解析纯真IP库(QQwry.dat) 支持IP段查询","archived":false,"fork":false,"pushed_at":"2024-03-18T09:08:24.000Z","size":49593,"stargazers_count":375,"open_issues_count":2,"forks_count":58,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-07-08T09:40:52.845Z","etag":null,"topics":["ip","qqwry"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cnwhy.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2013-06-09T02:03:33.000Z","updated_at":"2025-07-04T06:14:39.000Z","dependencies_parsed_at":"2024-04-12T11:01:48.429Z","dependency_job_id":"b3eed9b0-32a5-411b-bdc5-0e167467eeda","html_url":"https://github.com/cnwhy/lib-qqwry","commit_stats":{"total_commits":64,"total_committers":3,"mean_commits":"21.333333333333332","dds":0.03125,"last_synced_commit":"e27c15d93274cf7039e3bf3fefe7fc124bff53be"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/cnwhy/lib-qqwry","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnwhy%2Flib-qqwry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnwhy%2Flib-qqwry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnwhy%2Flib-qqwry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnwhy%2Flib-qqwry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cnwhy","download_url":"https://codeload.github.com/cnwhy/lib-qqwry/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnwhy%2Flib-qqwry/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264545157,"owners_count":23625403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ip","qqwry"],"created_at":"2024-08-04T14:00:54.594Z","updated_at":"2025-07-10T07:31:04.343Z","avatar_url":"https://github.com/cnwhy.png","language":"JavaScript","funding_links":[],"categories":["JavaScript (485)","JavaScript","目录"],"sub_categories":[],"readme":"# lib-qqwry\n\n`lib-qqwry`是一个高效纯真IP库(qqwry.dat)引擎;  \n\n## 安装\n```\nnpm i lib-qqwry\n```\n\n## 使用\n\n### cli (v1.3.0+) \n从1.3版本开始支持命令模式, 你可以用把`lib-qqwry`安装到全局来使用;\n![search](https://cnwhy.github.io/gh-res/images/qqwry-cli-search.svg)\n\n * `qqwry search \u003cip\u003e [ips...]` 查询IP/IP段\n * `qqwry find \u003ckeyword\u003e [keyword...]` 反查IP段\n    \n### node\n\n```js \nvar libqqwry = require('lib-qqwry');\nvar qqwry = libqqwry() //初始化IP库解析器\nqqwry.speed(); //启用急速模式;\n\nvar ip1 = qqwry.searchIP(\"202.103.102.10\"); //查询IP信息\nvar ips = qqwry.searchIPScope(\"0.0.0.0\",\"1.0.0.0\");  //查询IP段信息\n//异步查询IP段信息\nqqwry.searchIPScope(\"0.0.0.0\",\"1.0.0.0\",function(err,iparr){\n  console.log(iparr);\n});\n//查询IP段信息,结果以可读流返回\nvar ipStream = qqwry.searchIPScopeStream('0.0.0.0','1.0.0.0',{format:'json'});\n// s.pipe(fs.readFileSync(outFile))\nipStream.pipe(process.stdout)\n```\n\n## API\n\n### libqqwry.ipToInt(IP) IP地址转数值\n```\n\u003e libqqwry.ipToInt(\"255.255.255.255\")\n4294967295\n```\n\n### libqqwry.intToIP(INT) 数值转IP地址\n```\n\u003e libqqwry.intToIP(4294967295)\n'255.255.255.255'\n```\n\n### libqqwry.ipEndianChange(INT) 字节序转换\n按32位转换参数的字节序  \n一些云平台的环境变量中IP信息可能是Little-Endian形式的数值; \n\n```\n\u003e libqqwry.ipEndianChange(0x010000FF)\n4278190081 //0xFF000001\n```\n\n### new libqqwry(speed,dataPath) 实例化一个IP库解析器对像(Qqwry)\nspeed : 是否开启急速模式,可选; //默认false;  \ndataPath : IP库路径,可选; //默认路径为data文件夹中(__dirname + \"/data/qqwry.dat\");\n// 可以简写为 libqqwry(speed,dataPath)\n```js\nvar libqqwry = require('lib-qqwry');\nvar qqwry = libqqwry(true);\n```\n*libqqwry(), libqqwry.init()* 功能相同\n\n## 解析器对像 Qqwry\n### qqwry.searchIP(IP) 单个IP查询\nIP : IP地址/IP数值  \n\u003e 便捷调用: `qqwry(IP)` v1.2.0+\n\n```\n\u003e qqwry(\"255.255.255.255\");\n{ int: 4294967295,\n  ip: '255.255.255.255',\n  Country: '纯真网络',\n  Area: '2017年1月5日IP数据' }\n```\n\n### qqwry.searchIPScope(beginIP,endIP,[callback]) IP段查询\nbeginIP : 启始IP  \nendIP : 结束IP  \ncallback: function(err,arrdata){} 没有回调则使用同步查询;  \n\u003e 便捷调用: `qqwry(beginIP,endIP,callback)` v1.2.0+\n\n```\n\u003e qqwry(\"8.8.8.0\",\"8.8.8.8\");\n[ { begInt: 134744064,\n    endInt: 134744071,\n    begIP: '8.8.8.0',\n    endIP: '8.8.8.7',\n    Country: '美国',\n    Area: '加利福尼亚州圣克拉拉县山景市谷歌公司' },\n  { begInt: 134744072,\n    endInt: 134744072,\n    begIP: '8.8.8.8',\n    endIP: '8.8.8.8',\n    Country: '美国',\n    Area: '加利福尼亚州圣克拉拉县山景市谷歌公司DNS服务器' } ]\n```\n\n### qqwry.searchIPScopeStream(beginIP,endIP,options) 流形式反回IP段结果 v1.3.0+\n`beginIP` : \u003cstring|int\u003e // 启始IP  \n`endIP` : \u003cstring|int\u003e   // 结束IP  \n`options`:\n - `format` : \u003cstring\u003e //输出格式, 支持 'text' , 'csv', 'json', 'object'  \n - `outHeader`: \u003cboolean\u003e //为`true`时 'csv' 会输出表头 , 'json' 会以对像数组形式输出(参考`searchIPScope`方法); 默认 `false`\n\n\u003e 流模式适合查询结果数据量较大的情况使用  \n\u003e format说明: 'csv' , 'json' 格式适合直接输出到文件, 'object' 将返回对像流, 适合程序二次处理数据\n\n```shell\n\u003e qqwry.searchIPScopeStream(\"8.8.8.0\",\"8.8.8.8\").pipe(process.stdout);\n8.8.8.0 - 8.8.8.7                   美国 加利福尼亚州圣克拉拉县山景市谷歌公司\n8.8.8.8 - 8.8.8.8                   美国 加利福尼亚州圣克拉拉县山景市谷歌公司DNS服务器\n\n\u003e qqwry.searchIPScopeStream(\"8.8.8.0\",\"8.8.8.8\",{format:'csv'}).pipe(process.stdout);\n134744064,134744071,8.8.8.0,8.8.8.7,美国,加利福尼亚州圣克拉拉县山景市谷歌公司\n134744072,134744072,8.8.8.8,8.8.8.8,美国,加利福尼亚州圣克拉拉县山景市谷歌公司DNS服务器\n\n\u003e qqwry.searchIPScopeStream(\"8.8.8.0\",\"8.8.8.8\",{format:'json'}).pipe(process.stdout);\n[[134744064,134744071,\"8.8.8.0\",\"8.8.8.7\",\"美国\",\"加利福尼亚州圣克拉拉县山景市谷歌公司\"],[134744072,134744072,\"8.8.8.8\",\"8.8.8.8\",\"美国\",\"加利福尼亚州圣克拉拉县山景市谷歌公司DNS服务器\"]]\n```\n\n### qqwry.speed() 启用急速模式\n急速模式实质为将IP库文件读入内存中以提升效率.\n\n### qqwry.unSpeed() 停用急速模式\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcnwhy%2Flib-qqwry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcnwhy%2Flib-qqwry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcnwhy%2Flib-qqwry/lists"}