mirror of
https://github.com/metowolf/iplist.git
synced 2025-12-21 17:24:37 +08:00
新增运营商数据解析
This commit is contained in:
@@ -5,6 +5,7 @@ const plugin_city = require('./plugins/city')
|
||||
const plugin_cncity = require('./plugins/cncity')
|
||||
const plugin_china = require('./plugins/china')
|
||||
const plugin_cidrmerge = require('./plugins/cidrmerge')
|
||||
const plugin_isp = require('./plugins/isp')
|
||||
|
||||
const database = '/tmp/openipdb.ipdb'
|
||||
|
||||
@@ -35,6 +36,15 @@ const cncity = () => {
|
||||
.pipe(dest('data/cncity'))
|
||||
}
|
||||
|
||||
const isp = () => {
|
||||
return src(database)
|
||||
.pipe(through2.obj(function(file, _, cb) {
|
||||
return plugin_isp(this, file, cb)
|
||||
}))
|
||||
.pipe(through2.obj(plugin_cidrmerge))
|
||||
.pipe(dest('data/isp'))
|
||||
}
|
||||
|
||||
const china = () => {
|
||||
return src('data/country/CN.txt')
|
||||
.pipe(through2.obj(function(file, _, cb) {
|
||||
@@ -47,4 +57,5 @@ exports.country = country
|
||||
exports.city = city
|
||||
exports.cncity = cncity
|
||||
exports.china = china
|
||||
exports.build = series(country, city, cncity, china)
|
||||
exports.isp = isp
|
||||
exports.build = series(country, city, cncity, isp, china)
|
||||
|
||||
59
src/plugins/isp.js
Normal file
59
src/plugins/isp.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const vinyl = require('vinyl')
|
||||
const IPDB = require('ipdb')
|
||||
const ipdb_range = require('@ipdb/range')
|
||||
const ProgressBar = require('progress')
|
||||
|
||||
const ISP_MAP = {
|
||||
// 中国电信
|
||||
'chinatelecom.com.cn': 'chinatelecom',
|
||||
// 中国联通
|
||||
'chinaunicom.com': 'chinaunicom',
|
||||
// 中国移动
|
||||
'chinamobile.com': 'chinamobile',
|
||||
// 中国教育网
|
||||
'cernet.edu.cn': 'cernet',
|
||||
}
|
||||
|
||||
const plugin = (through2, file, cb) => {
|
||||
|
||||
console.log('Parse ipdb')
|
||||
|
||||
const ipdb = new IPDB(file.contents, {
|
||||
patches: [ipdb_range]
|
||||
})
|
||||
|
||||
let bar = new ProgressBar(':bar :current/:total', { total: ipdb.meta.node_count })
|
||||
|
||||
let result = []
|
||||
let ip = '0.0.0.0'
|
||||
while (true) {
|
||||
const info = ipdb.find(ip).data
|
||||
const isp = info.isp_domain || ''
|
||||
if (isp.length > 0 && ISP_MAP[isp]) {
|
||||
const ispName = ISP_MAP[isp]
|
||||
if (!result[ispName]) {
|
||||
result[ispName] = []
|
||||
}
|
||||
result[ispName].push(`${info.range.from}/${info.bitmask}`)
|
||||
}
|
||||
bar.tick()
|
||||
ip = info.range.next
|
||||
if (ip === '0.0.0.0') break
|
||||
}
|
||||
|
||||
console.log()
|
||||
|
||||
for (let [isp, cidrs] of Object.entries(result)) {
|
||||
let temp = new vinyl({
|
||||
cwd: '/',
|
||||
base: '/',
|
||||
path: `/${isp}.txt`,
|
||||
contents: new Buffer.from(cidrs.join('\n'))
|
||||
})
|
||||
through2.push(temp)
|
||||
}
|
||||
|
||||
cb()
|
||||
}
|
||||
|
||||
module.exports = plugin
|
||||
Reference in New Issue
Block a user