Skip to content

Commit

Permalink
feat: add support for standard IP database packaging and publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
metowolf committed Jan 5, 2025
1 parent 33f13ed commit f38cc82
Show file tree
Hide file tree
Showing 4 changed files with 341 additions and 2 deletions.
14 changes: 12 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -e

mkdir -p build/raw
mkdir -p build/stand

wget "https://www.cz88.net/api/communityIpAuthorization/communityIpDbFile?fn=czdb&key=${CZDB_DOWNLOAD_TOKEN}" -O build/czdb.zip
unzip build/czdb.zip -d build/
Expand All @@ -11,10 +12,19 @@ node src/packer_raw.js
ls -alh build/raw

LATEST_VERSION=`node src/version.js`
CURRENT_VERSION=`curl https://registry.npmjs.org/qqwry.raw.ipdb | jq -r '."dist-tags".latest'`

if [ $CURRENT_VERSION != $LATEST_VERSION ]; then
RAW_CURRENT_VERSION=`curl https://registry.npmjs.org/qqwry.raw.ipdb | jq -r '."dist-tags".latest'`
if [ $RAW_CURRENT_VERSION != $LATEST_VERSION ]; then
cp README.md build/raw/README.md
cd build/raw
npm publish
fi

STANDARD_CURRENT_VERSION=`curl https://registry.npmjs.org/qqwry.ipdb | jq -r '."dist-tags".latest'`
if [ $STANDARD_CURRENT_VERSION != $LATEST_VERSION ]; then
node src/packer_stand.js
ls -alh build/stand
cp README.md build/stand/README.md
cd build/stand
npm publish
fi
252 changes: 252 additions & 0 deletions src/format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
const COUNTRY_CODE = {
'安道尔': ['AD', 'EU', 'Europe/Andorra', 'UTC+1', '376'],
'阿联酋': ['AE', 'AP', 'Asia/Kuala_Lumpur', 'UTC+8', '971'],
'阿富汗': ['AF', 'AP', 'Asia/Kabul', 'UTC+4:30', '93'],
'安提瓜和巴布达': ['AG', 'NA', 'America/Antigua', 'UTC-4', '1268'],
'安圭拉': ['AI', 'LA', 'America/Anguilla', 'UTC-4', '1264'],
'阿尔巴尼亚': ['AL', 'EU', 'Europe/Tirane', 'UTC+1', '355'],
'亚美尼亚': ['AM', 'AP', 'Asia/Yerevan', 'UTC+4', '374'],
'安哥拉': ['AO', 'AF', 'Africa/Luanda', 'UTC+1', '244'],
'南极洲': ['AQ', 'AQ', 'America/Argentina/Buenos_Aires', 'UTC-3', '672'],
'阿根廷': ['AR', 'LA', 'America/Argentina/Buenos_Aires', 'UTC-3', '54'],
'美属萨摩亚': ['AS', 'AP', 'Pacific/Pago_Pago', 'UTC-11', '1684'],
'奥地利': ['AT', 'EU', 'Europe/Vienna', 'UTC+1', '43'],
'澳大利亚': ['AU', 'AP', 'Australia/Sydney', 'UTC+11', '61'],
'阿鲁巴': ['AW', 'LA', 'America/Aruba', 'UTC-4', '297'],
'奥兰群岛': ['AX', 'EU', 'Europe/Helsinki', 'UTC+2', '35818'],
'阿塞拜疆': ['AZ', 'AP', 'Asia/Baku', 'UTC+4', '994'],
'波斯尼亚和黑塞哥维那': ['BA', 'EU', 'Europe/Belgrade', 'UTC+1', '387'],
'巴巴多斯': ['BB', 'NA', 'America/Barbados', 'UTC-4', '1246'],
'孟加拉': ['BD', 'AP', 'Asia/Dhaka', 'UTC+6', '880'],
'比利时': ['BE', 'EU', 'Europe/Brussels', 'UTC+1', '32'],
'布基纳法索': ['BF', 'AF', 'Africa/Ouagadougou', 'UTC-0', '226'],
'保加利亚': ['BG', 'EU', 'Europe/Sofia', 'UTC+2', '359'],
'巴林': ['BH', 'AP', 'Asia/Bahrain', 'UTC+3', '973'],
'布隆迪': ['BI', 'AF', 'Africa/Bujumbura', 'UTC+2', '257'],
'贝宁': ['BJ', 'AF', 'Africa/Porto-Novo', 'UTC+1', '229'],
'圣巴泰勒米': ['BL', 'LA', 'America/Guadeloupe', 'UTC-4', '590'],
'百慕大': ['BM', 'LA', 'Atlantic/Bermuda', 'UTC-4', '1441'],
'文莱': ['BN', 'AP', 'Asia/Brunei', 'UTC+8', '673'],
'玻利维亚': ['BO', 'LA', 'America/La_Paz', 'UTC-4', '591'],
'荷兰加勒比': ['BQ', 'LA', 'America/Curacao', 'UTC-4', '5997'],
'巴西': ['BR', 'LA', 'America/Sao_Paulo', 'UTC-2', '55'],
'巴哈马': ['BS', 'NA', 'America/Nassau', 'UTC-5', '1242'],
'不丹': ['BT', 'AP', 'Asia/Thimphu', 'UTC+6', '975'],
'博茨瓦纳': ['BW', 'AF', 'Africa/Gaborone', 'UTC+2', '267'],
'白俄罗斯': ['BY', 'EU', 'Europe/Minsk', 'UTC+3', '375'],
'伯利兹': ['BZ', 'NA', 'America/Belize', 'UTC-6', '501'],
'加拿大': ['CA', 'NA', 'America/Toronto', 'UTC-5', '1'],
'刚果民主共和国': ['CD', 'AF', 'Africa/Kinshasa', 'UTC+1', '243'],
'中非': ['CF', 'AF', 'Africa/Bangui', 'UTC+1', '236'],
'刚果共和国': ['CG', 'AF', 'Africa/Brazzaville', 'UTC+1', '242'],
'瑞士': ['CH', 'EU', 'Europe/Zurich', 'UTC+1', '41'],
'科特迪瓦': ['CI', 'AF', 'Africa/Abidjan', 'UTC-0', '225'],
'库克群岛': ['CK', 'AP', 'Pacific/Rarotonga', 'UTC-10', '682'],
'智利': ['CL', 'LA', 'America/Santiago', 'UTC-3', '56'],
'喀麦隆': ['CM', 'AF', 'Africa/Douala', 'UTC+1', '237'],
'中国': ['CN', 'AP', 'Asia/Shanghai', 'UTC+8', '86'],
'哥伦比亚': ['CO', 'LA', 'America/Bogota', 'UTC-5', '57'],
'哥斯达黎加': ['CR', 'NA', 'America/Costa_Rica', 'UTC-6', '506'],
'古巴': ['CU', 'NA', 'America/Havana', 'UTC-5', '53'],
'佛得角': ['CV', 'AF', 'Atlantic/Cape_Verde', 'UTC-1', '238'],
'库拉索': ['CW', 'LA', 'America/Curacao', 'UTC-4', '5999'],
'圣诞岛': ['CX', 'AP', 'Indian/Christmas', 'UTC+7', '61'],
'塞浦路斯': ['CY', 'AP', 'Asia/Nicosia', 'UTC+2', '357'],
'捷克': ['CZ', 'EU', 'Europe/Prague', 'UTC+1', '420'],
'德国': ['DE', 'EU', 'Europe/Berlin', 'UTC+1', '49'],
'吉布提': ['DJ', 'AF', 'Africa/Djibouti', 'UTC+3', '253'],
'丹麦': ['DK', 'EU', 'Europe/Copenhagen', 'UTC+1', '45'],
'多米尼克': ['DM', 'NA', 'America/Dominica', 'UTC-4', '1767'],
'多米尼加': ['DO', 'NA', 'America/Santo_Domingo', 'UTC-4', '1809'],
'阿尔及利亚': ['DZ', 'AF', 'Africa/Algiers', 'UTC+1', '213'],
'厄瓜多尔': ['EC', 'LA', 'America/Guayaquil', 'UTC-5', '593'],
'爱沙尼亚': ['EE', 'EU', 'Europe/Tallinn', 'UTC+2', '372'],
'埃及': ['EG', 'AF', 'Africa/Cairo', 'UTC+2', '20'],
'厄立特里亚': ['ER', 'AF', 'Africa/Asmara', 'UTC+3', '291'],
'西班牙': ['ES', 'EU', 'Europe/Madrid', 'UTC+1', '34'],
'埃塞俄比亚': ['ET', 'AF', 'Africa/Addis_Ababa', 'UTC+3', '251'],
'芬兰': ['FI', 'EU', 'Europe/Helsinki', 'UTC+2', '358'],
'斐济': ['FJ', 'AP', 'Pacific/Fiji', 'UTC+12', '679'],
'福克兰群岛': ['FK', 'LA', 'Atlantic/Stanley', 'UTC-3', '500'],
'密克罗尼西亚联邦': ['FM', 'AP', 'Pacific/Pohnpei', 'UTC+11', '691'],
'法罗群岛': ['FO', 'EU', 'Atlantic/Faroe', 'UTC-0', '298'],
'法国': ['FR', 'EU', 'Europe/Paris', 'UTC+1', '33'],
'加蓬': ['GA', 'AF', 'Africa/Libreville', 'UTC+1', '241'],
'英国': ['GB', 'EU', 'Europe/London', 'UTC-0', '44'],
'格林纳达': ['GD', 'NA', 'America/Grenada', 'UTC-4', '1473'],
'格鲁吉亚': ['GE', 'AP', 'Asia/Tbilisi', 'UTC+4', '995'],
'法属圭亚那': ['GF', 'LA', 'America/Cayenne', 'UTC-3', '594'],
'根西岛': ['GG', 'EU', 'Europe/London', 'UTC-0', '441481'],
'加纳': ['GH', 'AF', 'Africa/Accra', 'UTC-0', '233'],
'直布罗陀': ['GI', 'EU', 'Europe/Gibraltar', 'UTC+1', '350'],
'格陵兰': ['GL', 'EU', 'America/Godthab', 'UTC-3', '299'],
'冈比亚': ['GM', 'AF', 'Africa/Banjul', 'UTC-0', '220'],
'几内亚': ['GN', 'AF', 'Africa/Conakry', 'UTC-0', '224'],
'瓜德罗普': ['GP', 'LA', 'America/Guadeloupe', 'UTC-4', '590'],
'赤道几内亚': ['GQ', 'AF', 'Africa/Malabo', 'UTC+1', '240'],
'希腊': ['GR', 'EU', 'Europe/Athens', 'UTC+2', '30'],
'危地马拉': ['GT', 'NA', 'America/Guatemala', 'UTC-6', '502'],
'关岛': ['GU', 'AP', 'Pacific/Guam', 'UTC+10', '1671'],
'几内亚比绍': ['GW', 'AF', 'Africa/Bissau', 'UTC-0', '245'],
'圭亚那': ['GY', 'LA', 'America/Guyana', 'UTC-4', '592'],
'中国-香港': ['HK', 'AP', 'Asia/Hong_Kong', 'UTC+8', '852'],
'洪都拉斯': ['HN', 'NA', 'America/Tegucigalpa', 'UTC-6', '504'],
'克罗地亚': ['HR', 'EU', 'Europe/Belgrade', 'UTC+1', '385'],
'海地': ['HT', 'NA', 'America/Port-au-Prince', 'UTC-5', '509'],
'匈牙利': ['HU', 'EU', 'Europe/Budapest', 'UTC+1', '36'],
'印度尼西亚': ['ID', 'AP', 'Asia/Jakarta', 'UTC+7', '62'],
'爱尔兰': ['IE', 'EU', 'Europe/Dublin', 'UTC-0', '353'],
'以色列': ['IL', 'AP', 'Asia/Jerusalem', 'UTC+2', '972'],
'马恩岛': ['IM', 'EU', 'Europe/London', 'UTC-0', '441624'],
'印度': ['IN', 'AP', 'Asia/Kolkata', 'UTC+5:30', '91'],
'英属印度洋领地': ['IO', 'EU', 'Indian/Chagos', 'UTC+6', '246'],
'伊拉克': ['IQ', 'AP', 'Asia/Baghdad', 'UTC+3', '964'],
'伊朗': ['IR', 'AP', 'Asia/Tehran', 'UTC+3:30', '98'],
'冰岛': ['IS', 'EU', 'Atlantic/Reykjavik', 'UTC-0', '354'],
'意大利': ['IT', 'EU', 'Europe/Rome', 'UTC+1', '39'],
'泽西岛': ['JE', 'EU', 'Europe/London', 'UTC-0', '441534'],
'牙买加': ['JM', 'NA', 'America/Jamaica', 'UTC-5', '1876'],
'约旦': ['JO', 'AP', 'Asia/Amman', 'UTC+2', '962'],
'日本': ['JP', 'AP', 'Asia/Tokyo', 'UTC+9', '81'],
'肯尼亚': ['KE', 'AF', 'Africa/Nairobi', 'UTC+3', '254'],
'吉尔吉斯斯坦': ['KG', 'AP', 'Asia/Bishkek', 'UTC+6', '331'],
'柬埔寨': ['KH', 'AP', 'Asia/Phnom_Penh', 'UTC+7', '855'],
'基里巴斯': ['KI', 'AP', 'Pacific/Tarawa', 'UTC+12', '686'],
'科摩罗': ['KM', 'AF', 'Indian/Comoro', 'UTC+3', '269'],
'圣基茨和尼维斯': ['KN', 'NA', 'America/St_Kitts', 'UTC-4', '1869'],
'朝鲜': ['KP', 'AP', 'Asia/Pyongyang', 'UTC+9', '850'],
'韩国': ['KR', 'AP', 'Asia/Seoul', 'UTC+9', '82'],
'科威特': ['KW', 'AP', 'Asia/Kuwait', 'UTC+3', '965'],
'开曼群岛': ['KY', 'NA', 'America/Cayman', 'UTC-5', '1345'],
'哈萨克斯坦': ['KZ', 'AP', 'Asia/Almaty', 'UTC+6', '327'],
'老挝': ['LA', 'AP', 'Asia/Vientiane', 'UTC+7', '856'],
'黎巴嫩': ['LB', 'AP', 'Asia/Beirut', 'UTC+2', '961'],
'圣卢西亚': ['LC', 'NA', 'America/St_Lucia', 'UTC-4', '1758'],
'列支敦士登': ['LI', 'EU', 'Europe/Vaduz', 'UTC+1', '423'],
'斯里兰卡': ['LK', 'AP', 'Asia/Colombo', 'UTC+5:30', '94'],
'利比里亚': ['LR', 'AF', 'Africa/Monrovia', 'UTC-0', '231'],
'莱索托': ['LS', 'AF', 'Africa/Maseru', 'UTC+2', '266'],
'立陶宛': ['LT', 'EU', 'Europe/Vilnius', 'UTC+2', '370'],
'卢森堡': ['LU', 'EU', 'Europe/Luxembourg', 'UTC+1', '352'],
'拉脱维亚': ['LV', 'EU', 'Europe/Riga', 'UTC+2', '371'],
'利比亚': ['LY', 'AF', 'Africa/Tripoli', 'UTC+2', '218'],
'摩洛哥': ['MA', 'AF', 'Africa/Casablanca', 'UTC+1', '212'],
'摩纳哥': ['MC', 'EU', 'Europe/Monaco', 'UTC+1', '377'],
'摩尔多瓦': ['MD', 'EU', 'Europe/Chisinau', 'UTC+2', '373'],
'黑山': ['ME', 'EU', 'Europe/Belgrade', 'UTC+1', '382'],
'法属圣马丁': ['MF', 'LA', 'America/Lima', 'UTC-5', '1599'],
'马达加斯加': ['MG', 'AF', 'Indian/Antananarivo', 'UTC+3', '261'],
'马绍尔群岛': ['MH', 'AP', 'Pacific/Kwajalein', 'UTC+12', '692'],
'北马其顿': ['MK', 'EU', 'Europe/Belgrade', 'UTC+1', '389'],
'马里': ['ML', 'AF', 'Africa/Bamako', 'UTC-0', '223'],
'缅甸': ['MM', 'AP', 'Asia/Rangoon', 'UTC+6:30', '95'],
'蒙古': ['MN', 'AP', 'Asia/Ulaanbaatar', 'UTC+8', '976'],
'中国-澳门': ['MO', 'AP', 'Asia/Macau', 'UTC+8', '853'],
'北马里亚纳群岛': ['MP', 'AP', 'Pacific/Saipan', 'UTC+10', '1670'],
'马提尼克': ['MQ', 'LA', 'America/Martinique', 'UTC-4', '596'],
'毛里塔尼亚': ['MR', 'AF', 'Africa/Nouakchott', 'UTC-0', '222'],
'蒙特塞拉特岛': ['MS', 'LA', 'Europe/Madrid', 'UTC+1', '1664'],
'马耳他': ['MT', 'EU', 'Europe/Malta', 'UTC+1', '356'],
'毛里求斯': ['MU', 'AF', 'Indian/Mauritius', 'UTC+4', '230'],
'马尔代夫': ['MV', 'AP', 'Indian/Maldives', 'UTC+5', '960'],
'马拉维': ['MW', 'AF', 'Africa/Blantyre', 'UTC+2', '265'],
'墨西哥': ['MX', 'NA', 'America/Mexico_City', 'UTC-6', '52'],
'马来西亚': ['MY', 'AP', 'Asia/Kuala_Lumpur', 'UTC+8', '60'],
'莫桑比克': ['MZ', 'AF', 'Africa/Maputo', 'UTC+2', '258'],
'纳米比亚': ['NA', 'AF', 'Africa/Windhoek', 'UTC+2', '264'],
'新喀里多尼亚': ['NC', 'AP', 'Pacific/Noumea', 'UTC+11', '687'],
'尼日尔': ['NE', 'AF', 'Africa/Niamey', 'UTC+1', '227'],
'诺福克岛': ['NF', 'AP', 'Pacific/Norfolk', 'UTC+11', '672'],
'尼日利亚': ['NG', 'AF', 'Africa/Lagos', 'UTC+1', '234'],
'尼加拉瓜': ['NI', 'NA', 'America/Managua', 'UTC-6', '505'],
'荷兰': ['NL', 'EU', 'Europe/Amsterdam', 'UTC+1', '31'],
'挪威': ['NO', 'EU', 'Europe/Oslo', 'UTC+1', '47'],
'尼泊尔': ['NP', 'AP', 'Asia/Kathmandu', 'UTC+5:45', '977'],
'瑙鲁': ['NR', 'AP', 'Pacific/Nauru', 'UTC+12', '674'],
'纽埃': ['NU', 'AP', 'Pacific/Niue', 'UTC-11', '683'],
'新西兰': ['NZ', 'AP', 'Pacific/Auckland', 'UTC+13', '64'],
'阿曼': ['OM', 'AP', 'Asia/Muscat', 'UTC+4', '968'],
'巴拿马': ['PA', 'NA', 'America/Panama', 'UTC-5', '507'],
'秘鲁': ['PE', 'LA', 'America/Lima', 'UTC-5', '51'],
'法属波利尼西亚': ['PF', 'AP', 'Pacific/Tahiti', 'UTC-10', '689'],
'巴布亚新几内亚': ['PG', 'AP', 'Pacific/Port_Moresby', 'UTC+10', '675'],
'菲律宾': ['PH', 'AP', 'Asia/Manila', 'UTC+8', '63'],
'巴基斯坦': ['PK', 'AP', 'Asia/Karachi', 'UTC+5', '92'],
'波兰': ['PL', 'EU', 'Europe/Warsaw', 'UTC+1', '48'],
'圣皮埃尔和密克隆群岛': ['PM', 'NA', 'America/Miquelon', 'UTC-3', '508'],
'波多黎各': ['PR', 'NA', 'America/Puerto_Rico', 'UTC-4', '1787/1939'],
'巴勒斯坦': ['PS', 'AP', 'Asia/Gaza', 'UTC+2', '970'],
'葡萄牙': ['PT', 'EU', 'Europe/Lisbon', 'UTC-0', '351'],
'帕劳': ['PW', 'AP', 'Pacific/Palau', 'UTC+9', '680'],
'巴拉圭': ['PY', 'LA', 'America/Asuncion', 'UTC-3', '595'],
'卡塔尔': ['QA', 'AP', 'Asia/Qatar', 'UTC+3', '974'],
'留尼汪岛': ['RE', 'AF', 'Indian/Reunion', 'UTC+4', '262'],
'罗马尼亚': ['RO', 'EU', 'Europe/Bucharest', 'UTC+2', '40'],
'塞尔维亚': ['RS', 'EU', 'Europe/Belgrade', 'UTC+1', '381'],
'俄罗斯': ['RU', 'EU', 'Europe/Moscow', 'UTC+3', '7'],
'卢旺达': ['RW', 'AF', 'Africa/Kigali', 'UTC+2', '250'],
'沙特阿拉伯': ['SA', 'AP', 'Asia/Riyadh', 'UTC+3', '966'],
'所罗门群岛': ['SB', 'AP', 'Pacific/Guadalcanal', 'UTC+11', '677'],
'塞舌尔': ['SC', 'AF', 'Indian/Mahe', 'UTC+4', '248'],
'苏丹': ['SD', 'AF', 'Africa/Khartoum', 'UTC+2', '249'],
'瑞典': ['SE', 'EU', 'Europe/Stockholm', 'UTC+1', '46'],
'新加坡': ['SG', 'AP', 'Asia/Singapore', 'UTC+8', '65'],
'斯洛文尼亚': ['SI', 'EU', 'Europe/Belgrade', 'UTC+1', '386'],
'斯洛伐克': ['SK', 'EU', 'Europe/Prague', 'UTC+1', '421'],
'塞拉利昂': ['SL', 'AF', 'Africa/Freetown', 'UTC-0', '232'],
'圣马力诺': ['SM', 'EU', 'Europe/Rome', 'UTC+1', '378'],
'塞内加尔': ['SN', 'AF', 'Africa/Dakar', 'UTC-0', '221'],
'索马里': ['SO', 'AF', 'Africa/Mogadishu', 'UTC+3', '252'],
'苏里南': ['SR', 'LA', 'America/Paramaribo', 'UTC-3', '597'],
'南苏丹': ['SS', 'AF', 'Africa/Juba', 'UTC+3', '211'],
'圣多美和普林西比': ['ST', 'AF', 'Africa/Sao_Tome', 'UTC+1', '239'],
'萨尔瓦多': ['SV', 'NA', 'America/El_Salvador', 'UTC-6', '503'],
'荷属圣马丁': ['SX', 'NA', 'America/Guadeloupe', 'UTC-4', '1721'],
'叙利亚': ['SY', 'AP', 'Asia/Damascus', 'UTC+2', '963'],
'斯威士兰': ['SZ', 'AF', 'Africa/Mbabane', 'UTC+2', '268'],
'特克斯和凯科斯群岛': ['TC', 'NA', 'America/Grand_Turk', 'UTC-5', '1649'],
'乍得': ['TD', 'AF', 'Africa/Ndjamena', 'UTC+1', '235'],
'多哥': ['TG', 'AF', 'Africa/Lome', 'UTC-0', '228'],
'泰国': ['TH', 'AP', 'Asia/Bangkok', 'UTC+7', '66'],
'塔吉克斯坦': ['TJ', 'AP', 'Asia/Dushanbe', 'UTC+5', '992'],
'托克劳': ['TK', 'AP', 'Pacific/Fakaofo', 'UTC+13', '690'],
'东帝汶': ['TL', 'AP', 'Asia/Dili', 'UTC+9', '670'],
'土库曼斯坦': ['TM', 'AP', 'Asia/Ashgabat', 'UTC+5', '993'],
'突尼斯': ['TN', 'AF', 'Africa/Tunis', 'UTC+1', '216'],
'汤加': ['TO', 'AP', 'Pacific/Tongatapu', 'UTC+13', '676'],
'土耳其': ['TR', 'AP', 'Europe/Istanbul', 'UTC+3', '90'],
'特立尼达和多巴哥': ['TT', 'NA', 'America/Port_of_Spain', 'UTC-4', '1868'],
'图瓦卢': ['TV', 'AP', 'Pacific/Funafuti', 'UTC+12', '688'],
'中国-台湾': ['TW', 'AP', 'Asia/Taipei', 'UTC+8', '886'],
'坦桑尼亚': ['TZ', 'AF', 'Africa/Dar_es_Salaam', 'UTC+3', '255'],
'乌克兰': ['UA', 'EU', 'Europe/Kiev', 'UTC+2', '380'],
'乌干达': ['UG', 'AF', 'Africa/Kampala', 'UTC+3', '256'],
'美国': ['US', 'NA', 'America/New_York', 'UTC-5', '1'],
'乌拉圭': ['UY', 'LA', 'America/Montevideo', 'UTC-3', '598'],
'乌兹别克斯坦': ['UZ', 'AP', 'Asia/Samarkand', 'UTC+5', '233'],
'梵蒂冈': ['VA', 'EU', 'Europe/Rome', 'UTC+1', '39'],
'圣文森特和格林纳丁斯': ['VC', 'NA', 'America/St_Vincent', 'UTC-4', '1784'],
'委内瑞拉': ['VE', 'LA', 'America/Caracas', 'UTC-4', '58'],
'英属维尔京群岛': ['VG', 'NA', 'America/Tortola', 'UTC-4', '1284'],
'美属维尔京群岛': ['VI', 'NA', 'America/St_Thomas', 'UTC-4', '1340'],
'越南': ['VN', 'AP', 'Asia/Ho_Chi_Minh', 'UTC+7', '84'],
'瓦努阿图': ['VU', 'AP', 'Pacific/Efate', 'UTC+11', '678'],
'瓦利斯和富图纳群岛': ['WF', 'AP', 'Pacific/Wallis', 'UTC+12', '681'],
'萨摩亚': ['WS', 'AP', 'Pacific/Apia', 'UTC+14', '685'],
'科索沃': ['XK', 'EU', 'Europe/Belgrade', 'UTC+1', '383'],
'也门': ['YE', 'AP', 'Asia/Aden', 'UTC+3', '967'],
'马约特': ['YT', 'AF', 'Indian/Mayotte', 'UTC+3', '262'],
'南非': ['ZA', 'AF', 'Africa/Johannesburg', 'UTC+2', '27'],
'赞比亚': ['ZM', 'AF', 'Africa/Lusaka', 'UTC+2', '260'],
'津巴布韦': ['ZW', 'AF', 'Africa/Harare', 'UTC+2', '263'],
}

export function formatCountryCode(country, region) {
if (COUNTRY_CODE[country]) {
return COUNTRY_CODE[country][0]
} else if (COUNTRY_CODE[`${country}-${region}`]) {
return COUNTRY_CODE[`${country}-${region}`][0]
} else {
return ''
}
}
73 changes: 73 additions & 0 deletions src/packer_stand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import Decoder from '@ipdb/czdb'
import Packer from '@ipdb/packer'
import { range2cidrs } from './network.js'
import fs from 'node:fs'
import { formatCountryCode } from './format.js'

const files = [
{
version: 4,
file: './build/cz88_public_v4.czdb',
},
{
version: 6,
file: './build/cz88_public_v6.czdb',
}
]

const noCountryCodeSet = new Set()
const packer = new Packer({ipv6: true})
for (const file of files) {
const hash = {}
const decoder = new Decoder(file.file, process.env.CZDB_TOKEN)
decoder.dump(info => {
if (!hash[info.regionInfo]) {
hash[info.regionInfo] = []
}
const cidrs = range2cidrs(info.startIp, info.endIp, file.version)
hash[info.regionInfo].push(...cidrs)
})

for (const [info, cidrs] of Object.entries(hash)) {
console.log([cidrs[0], info].join('\t'))
const t = info.split('\t', 2)
// 信息
let country = '', region = '', city = '', district = '' , isp = '', owner = ''
if (t[0].includes('–')) {
const tt = t[0].split('–')
country = tt[0]
region = tt[1]
city = tt[2] || ''
district = tt[3] || ''
} else {
country = t[0]
}

if (t[1] && t[1].includes('/')) {
const tt = t[1].split('/')
isp = tt[0]
owner = tt[1] || ''
} else {
isp = t[1]
}

const country_code = formatCountryCode(country, region)
if (country_code === '') {
noCountryCodeSet.add(country)
}

for (const cidr of cidrs) {
packer.insert(cidr, [
country, region, city, district, owner, isp, country_code
])
}
}
}

console.log('存在以下未正确识别 CountryCode', noCountryCodeSet)

const chunk = packer.output([
'country_name', 'region_name', 'city_name', 'district_name', 'owner_domain', 'isp_domain', 'country_code'
])

fs.writeFileSync('./build/stand/qqwry.ipdb', chunk)
4 changes: 4 additions & 0 deletions src/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ json.version = version
json.name = 'qqwry.raw.ipdb'
fs.writeFileSync('./build/raw/index.js', index.trim())
fs.writeFileSync('./build/raw/package.json', JSON.stringify(json, null, ' '))

json.name = 'qqwry.ipdb'
fs.writeFileSync('./build/stand/index.js', index.trim())
fs.writeFileSync('./build/stand/package.json', JSON.stringify(json, null, ' '))

0 comments on commit f38cc82

Please sign in to comment.