ip2location-nodejs
Advanced tools
Comparing version 9.4.3 to 9.5.0
{ | ||
"name": "ip2location-nodejs", | ||
"version": "9.4.3", | ||
"version": "9.5.0", | ||
"description": "IP2Location geolocation component", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -6,3 +6,3 @@ [![npm](https://img.shields.io/npm/v/ip2location-nodejs.svg)](http://npm.im/ip2location-nodejs) | ||
This Node.js module provides a fast lookup of country, region, city, latitude, longitude, ZIP code, time zone, ISP, domain name, connection type, IDD code, area code, weather station code, station name, mcc, mnc, mobile brand, elevation, usage type, address type and IAB category from IP address by using IP2Location database. This module uses a file based database available at IP2Location.com. This database simply contains IP blocks as keys, and other information such as country, region, city, latitude, longitude, ZIP code, time zone, ISP, domain name, connection type, IDD code, area code, weather station code, station name, mcc, mnc, mobile brand, elevation, usage type, address type and IAB category as values. It supports both IP address in IPv4 and IPv6. | ||
This Node.js module provides a fast lookup of country, region, city, latitude, longitude, ZIP code, time zone, ISP, domain name, connection type, IDD code, area code, weather station code, station name, mcc, mnc, mobile brand, elevation, usage type, address type, IAB category, district, autonomous system number (ASN) and autonomous system (AS) from IP address by using IP2Location database. This module uses a file based database available at IP2Location.com. This database simply contains IP blocks as keys, and other information such as country, region, city, latitude, longitude, ZIP code, time zone, ISP, domain name, connection type, IDD code, area code, weather station code, station name, mcc, mnc, mobile brand, elevation, usage type, address type, IAB category, district, autonomous system number (ASN) and autonomous system (AS) as values. It supports both IP address in IPv4 and IPv6. | ||
@@ -85,2 +85,5 @@ This module can be used in many types of projects such as: | ||
|getCategory|Returns the IAB category.| | ||
|getDistrict|Returns the district name.| | ||
|getASN|Returns the autonomous system number (ASN).| | ||
|getAS|Returns the autonomous system (AS).| | ||
|close|Closes BIN file and resets metadata.| | ||
@@ -97,3 +100,3 @@ | ||
ip2location.open("./DB25.BIN"); | ||
ip2location.open("./DB26.BIN"); | ||
@@ -100,0 +103,0 @@ testip = ['8.8.8.8', '2404:6800:4001:c01::67']; |
@@ -157,2 +157,5 @@ export class IP2Location { | ||
category: string; | ||
district: string; | ||
asn: string; | ||
as: string; | ||
}; | ||
@@ -332,2 +335,23 @@ /** | ||
/** | ||
* Returns the district name. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The district name. | ||
*/ | ||
getDistrict(myIP: string): string; | ||
/** | ||
* Returns the autonomous system number (ASN). | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The ASN. | ||
*/ | ||
getASN(myIP: string): string; | ||
/** | ||
* Returns the autonomous system (AS). | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The AS. | ||
*/ | ||
getAS(myIP: string): string; | ||
/** | ||
* Returns all fields. | ||
@@ -363,2 +387,5 @@ * | ||
category: string; | ||
district: string; | ||
asn: string; | ||
as: string; | ||
}; | ||
@@ -365,0 +392,0 @@ #private; |
@@ -7,78 +7,100 @@ var net = require("net"); | ||
// For BIN queries | ||
const VERSION = "9.4.3"; | ||
const VERSION = "9.5.0"; | ||
const MAX_INDEX = 65536; | ||
const COUNTRY_POSITION = [ | ||
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | ||
2, | ||
]; | ||
const REGION_POSITION = [ | ||
0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | ||
3, | ||
]; | ||
const CITY_POSITION = [ | ||
0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | ||
4, | ||
]; | ||
const ISP_POSITION = [ | ||
0, 0, 3, 0, 5, 0, 7, 5, 7, 0, 8, 0, 9, 0, 9, 0, 9, 0, 9, 7, 9, 0, 9, 7, 9, 9, | ||
9, | ||
]; | ||
const LATITUDE_POSITION = [ | ||
0, 0, 0, 0, 0, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | ||
5, | ||
]; | ||
const LONGITUDE_POSITION = [ | ||
0, 0, 0, 0, 0, 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
6, | ||
]; | ||
const DOMAIN_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 6, 8, 0, 9, 0, 10, 0, 10, 0, 10, 0, 10, 8, 10, 0, 10, 8, | ||
10, 10, | ||
10, 10, 10, | ||
]; | ||
const ZIP_CODE_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 7, 7, 7, 0, 7, 0, 7, 7, 7, 0, 7, 7, | ||
7, | ||
]; | ||
const TIME_ZONE_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 7, 8, 8, 8, 7, 8, 0, 8, 8, 8, 0, 8, 8, | ||
8, | ||
]; | ||
const NET_SPEED_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 11, 0, 11, 8, 11, 0, 11, 0, 11, 0, | ||
11, 11, | ||
11, 11, 11, | ||
]; | ||
const IDD_CODE_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 12, 0, 12, 0, 12, 9, 12, 0, | ||
12, 12, | ||
12, 12, 12, | ||
]; | ||
const AREA_CODE_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 13, 0, 13, 0, 13, 10, 13, 0, | ||
13, 13, | ||
13, 13, 13, | ||
]; | ||
const WEATHER_STATION_CODE_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 14, 0, 14, 0, 14, 0, 14, | ||
14, | ||
14, 14, | ||
]; | ||
const WEATHER_STATION_NAME_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 15, 0, 15, 0, 15, 0, | ||
15, 15, | ||
15, 15, 15, | ||
]; | ||
const MCC_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 16, 0, 16, 9, 16, | ||
16, | ||
16, 16, | ||
]; | ||
const MNC_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 17, 0, 17, 10, | ||
17, 17, | ||
17, 17, 17, | ||
]; | ||
const MOBILE_BRAND_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 18, 0, 18, 11, | ||
18, 18, | ||
18, 18, 18, | ||
]; | ||
const ELEVATION_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 19, 0, 19, | ||
19, | ||
19, 19, | ||
]; | ||
const USAGE_TYPE_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 20, | ||
20, | ||
20, 20, | ||
]; | ||
const ADDRESS_TYPE_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, | ||
21, | ||
]; | ||
const CATEGORY_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, | ||
22, | ||
]; | ||
const DISTRICT_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
23, | ||
]; | ||
const ASN_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
24, | ||
]; | ||
const AS_POSITION = [ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
25, | ||
]; | ||
const MAX_IPV4_RANGE = BigInt(4294967295); | ||
@@ -115,2 +137,5 @@ const MAX_IPV6_RANGE = BigInt("340282366920938463463374607431768211455"); | ||
CATEGORY: 22, | ||
DISTRICT: 23, | ||
ASN: 24, | ||
AS: 25, | ||
ALL: 100, | ||
@@ -176,2 +201,5 @@ }; | ||
#categoryPositionOffset = 0; | ||
#districtPositionOffset = 0; | ||
#asnPositionOffset = 0; | ||
#asPositionOffset = 0; | ||
@@ -199,2 +227,5 @@ #countryEnabled = 0; | ||
#categoryEnabled = 0; | ||
#districtEnabled = 0; | ||
#asnEnabled = 0; | ||
#asEnabled = 0; | ||
@@ -441,2 +472,8 @@ #myDB = { | ||
CATEGORY_POSITION[dbt] != 0 ? (CATEGORY_POSITION[dbt] - 2) << 2 : 0; | ||
this.#districtPositionOffset = | ||
DISTRICT_POSITION[dbt] != 0 ? (DISTRICT_POSITION[dbt] - 2) << 2 : 0; | ||
this.#asnPositionOffset = | ||
ASN_POSITION[dbt] != 0 ? (ASN_POSITION[dbt] - 2) << 2 : 0; | ||
this.#asPositionOffset = | ||
AS_POSITION[dbt] != 0 ? (AS_POSITION[dbt] - 2) << 2 : 0; | ||
@@ -466,2 +503,5 @@ this.#countryEnabled = COUNTRY_POSITION[dbt] != 0 ? 1 : 0; | ||
this.#categoryEnabled = CATEGORY_POSITION[dbt] != 0 ? 1 : 0; | ||
this.#districtEnabled = DISTRICT_POSITION[dbt] != 0 ? 1 : 0; | ||
this.#asnEnabled = ASN_POSITION[dbt] != 0 ? 1 : 0; | ||
this.#asEnabled = AS_POSITION[dbt] != 0 ? 1 : 0; | ||
@@ -793,2 +833,21 @@ if (this.#myDB.indexed == 1) { | ||
} | ||
if (this.#districtEnabled) { | ||
if (mode == MODES.ALL || mode == MODES.DISTRICT) { | ||
data.district = this.readStr( | ||
this.read32Row(this.#districtPositionOffset, row) | ||
); | ||
} | ||
} | ||
if (this.#asnEnabled) { | ||
if (mode == MODES.ALL || mode == MODES.ASN) { | ||
data.asn = this.readStr( | ||
this.read32Row(this.#asnPositionOffset, row) | ||
); | ||
} | ||
} | ||
if (this.#asEnabled) { | ||
if (mode == MODES.ALL || mode == MODES.AS) { | ||
data.as = this.readStr(this.read32Row(this.#asPositionOffset, row)); | ||
} | ||
} | ||
return; | ||
@@ -833,2 +892,5 @@ } else { | ||
category: "?", | ||
district: "?", | ||
asn: "?", | ||
as: "?", | ||
}; | ||
@@ -1020,2 +1082,20 @@ | ||
// Return a string for the district name | ||
getDistrict(myIP) { | ||
let data = this.geoQuery(myIP, MODES.DISTRICT); | ||
return data.district; | ||
} | ||
// Return a string for the autonomous system number (ASN) | ||
getASN(myIP) { | ||
let data = this.geoQuery(myIP, MODES.ASN); | ||
return data.asn; | ||
} | ||
// Return a string for the autonomous system (AS) | ||
getAS(myIP) { | ||
let data = this.geoQuery(myIP, MODES.AS); | ||
return data.as; | ||
} | ||
// Return all results | ||
@@ -1022,0 +1102,0 @@ getAll(myIP) { |
@@ -5,3 +5,3 @@ const {IP2Location, IP2LocationWebService, IPTools, Country, Region} = require("ip2location-nodejs"); | ||
ip2location.open("./DB25.BIN"); | ||
ip2location.open("./DB26.BIN"); | ||
@@ -38,2 +38,5 @@ testip = ['2001:0:4136:e378:8000:63bf:f7f7:f7f7', '2002:0803:2200::0803:2200']; | ||
console.log("category: " + ip2location.getCategory(testip[x])); | ||
console.log("district: " + ip2location.getDistrict(testip[x])); | ||
console.log("asn: " + ip2location.getASN(testip[x])); | ||
console.log("as: " + ip2location.getAS(testip[x])); | ||
console.log("=================================================================="); | ||
@@ -40,0 +43,0 @@ } |
81001
2173
252