ip2location-nodejs
Advanced tools
Comparing version 9.5.0 to 9.6.0
{ | ||
"name": "ip2location-nodejs", | ||
"version": "9.5.0", | ||
"version": "9.6.0", | ||
"description": "IP2Location geolocation component", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
227
README.md
@@ -27,226 +27,3 @@ [![npm](https://img.shields.io/npm/v/ip2location-nodejs.svg)](http://npm.im/ip2location-nodejs) | ||
## Installation | ||
To install this module type the following: | ||
```bash | ||
npm install ip2location-nodejs | ||
``` | ||
## QUERY USING THE BIN FILE | ||
## Dependencies | ||
This library requires IP2Location BIN data file to function. You may download the BIN data file at | ||
* IP2Location LITE BIN Data (Free): https://lite.ip2location.com | ||
* IP2Location Commercial BIN Data (Comprehensive): https://www.ip2location.com | ||
## IPv4 BIN vs IPv6 BIN | ||
Use the IPv4 BIN file if you just need to query IPv4 addresses. | ||
If you query an IPv6 address using the IPv4 BIN, you'll see the IPV6_NOT_SUPPORTED error. | ||
Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses. | ||
## Methods | ||
Below are the methods supported in this module. | ||
|Method Name|Description| | ||
|---|---| | ||
|open|Opens the IP2Location BIN data for lookup.| | ||
|getAll|Returns the geolocation information in an object.| | ||
|getCountryShort|Returns the country code.| | ||
|getCountryLong|Returns the country name.| | ||
|getRegion|Returns the region name.| | ||
|getCity|Returns the city name.| | ||
|getISP|Returns the ISP name.| | ||
|getLatitude|Returns the latitude.| | ||
|getLongitude|Returns the longitude.| | ||
|getDomain|Returns the domain name.| | ||
|getZIPCode|Returns the ZIP code.| | ||
|getTimeZone|Returns the time zone.| | ||
|getNetSpeed|Returns the net speed.| | ||
|getIDDCode|Returns the IDD code.| | ||
|getAreaCode|Returns the area code.| | ||
|getWeatherStationCode|Returns the weather station code.| | ||
|getWeatherStationName|Returns the weather station name.| | ||
|getMCC|Returns the mobile country code.| | ||
|getMNC|Returns the mobile network code.| | ||
|getMobileBrand|Returns the mobile brand.| | ||
|getElevation|Returns the elevation in meters.| | ||
|getUsageType|Returns the usage type.| | ||
|getAddressType|Returns the address type.| | ||
|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.| | ||
## Usage | ||
```javascript | ||
const {IP2Location} = require("ip2location-nodejs"); | ||
let ip2location = new IP2Location(); | ||
ip2location.open("./DB26.BIN"); | ||
testip = ['8.8.8.8', '2404:6800:4001:c01::67']; | ||
for (var x = 0; x < testip.length; x++) { | ||
result = ip2location.getAll(testip[x]); | ||
for (var key in result) { | ||
console.log(key + ": " + result[key]); | ||
} | ||
console.log("--------------------------------------------------------------"); | ||
} | ||
ip2location.close(); | ||
``` | ||
## QUERY USING THE IP2LOCATION WEB SERVICE | ||
## Methods | ||
Below are the methods supported in this module. | ||
|Method Name|Description| | ||
|---|---| | ||
|open| 3 input parameters:<ol><li>IP2Location API Key.</li><li>Package (WS1 - WS25)</li></li><li>Use HTTPS or HTTP</li></ol> | | ||
|lookup|Query IP address. This method returns an object containing the geolocation info. <ul><li>country_code</li><li>country_name</li><li>region_name</li><li>city_name</li><li>latitude</li><li>longitude</li><li>zip_code</li><li>time_zone</li><li>isp</li><li>domain</li><li>net_speed</li><li>idd_code</li><li>area_code</li><li>weather_station_code</li><li>weather_station_name</li><li>mcc</li><li>mnc</li><li>mobile_brand</li><li>elevation</li><li>usage_type</li><li>address_type</li><li>category</li><li>continent<ul><li>name</li><li>code</li><li>hemisphere</li><li>translations</li></ul></li><li>country<ul><li>name</li><li>alpha3_code</li><li>numeric_code</li><li>demonym</li><li>flag</li><li>capital</li><li>total_area</li><li>population</li><li>currency<ul><li>code</li><li>name</li><li>symbol</li></ul></li><li>language<ul><li>code</li><li>name</li></ul></li><li>idd_code</li><li>tld</li><li>translations</li></ul></li><li>region<ul><li>name</li><li>code</li><li>translations</li></ul></li><li>city<ul><li>name</li><li>translations</li></ul></li><li>geotargeting<ul><li>metro</li></ul></li><li>country_groupings</li><li>time_zone_info<ul><li>olson</li><li>current_time</li><li>gmt_offset</li><li>is_dst</li><li>sunrise</li><li>sunset</li></ul></li><ul>| | ||
|getCredit()|This method returns the web service credit balance in an object.| | ||
## Usage | ||
```javascript | ||
const {IP2LocationWebService} = require("ip2location-nodejs"); | ||
let ws = new IP2LocationWebService(); | ||
let ip = "8.8.8.8"; | ||
let apiKey = "YOUR_API_KEY"; | ||
let apiPackage = "WS25"; | ||
let useSSL = true; | ||
// addon and lang to get more data and translation (leave both blank if you don't need them) | ||
let addon = "continent,country,region,city,geotargeting,country_groupings,time_zone_info"; | ||
let lang = "fr"; | ||
ws.open(apiKey, apiPackage, useSSL); | ||
ws.lookup(ip, addon, lang, (err, data) => { | ||
if (!err) { | ||
console.log(data); | ||
ws.getCredit((err, data) => { | ||
if (!err) { | ||
console.log(data); | ||
} | ||
}); | ||
} | ||
}); | ||
``` | ||
## IPTOOLS CLASS | ||
## Methods | ||
Below are the methods supported in this module. | ||
|Method Name|Description| | ||
|---|---| | ||
|isIPV4(myIP)|Returns true if string contains an IPv4 address. Otherwise false.| | ||
|isIPV6(myIP)|Returns true if string contains an IPv6 address. Otherwise false.| | ||
|ipV4ToDecimal(myIP)|Returns the IP number for an IPv4 address.| | ||
|ipV6ToDecimal(myIP)|Returns the IP number for an IPv6 address.| | ||
|decimalToIPV4(ipNum)|Returns the IPv4 address for the supplied IP number.| | ||
|decimalToIPV6(ipNum)|Returns the IPv6 address for the supplied IP number.| | ||
|compressIPV6(myIP)|Returns the IPv6 address in compressed form.| | ||
|expandIPV6(myIP)|Returns the IPv6 address in expanded form.| | ||
|ipV4ToCIDR(ipFrom, ipTo)|Returns a list of CIDR from the supplied IPv4 range.| | ||
|ipV6ToCIDR(ipFrom, ipTo)|Returns a list of CIDR from the supplied IPv6 range.| | ||
|cidrToIPV4(cidr)|Returns the IPv4 range from the supplied CIDR.| | ||
|cidrToIPV6(cidr)|Returns the IPv6 range from the supplied CIDR.| | ||
## Usage | ||
```javascript | ||
const {IPTools} = require("ip2location-nodejs"); | ||
let tools = new IPTools(); | ||
console.log(tools.isIPV4("60.54.166.38")); | ||
console.log(tools.isIPV6("2001:4860:4860::8888")); | ||
console.log(tools.ipV4ToDecimal("60.54.166.38")); | ||
console.log(tools.ipV6ToDecimal("2001:4860:4860::8888")); | ||
console.log(tools.decimalToIPV4(1010214438)); | ||
console.log(tools.decimalToIPV6("530610913025797008819807084026527744")); | ||
console.log(tools.compressIPV6("66:3123:4860:3234:411:23:000:000")); | ||
console.log(tools.expandIPV6("66:023:40:34:411:23:000:000")); | ||
let cidr = tools.ipV4ToCIDR("10.0.0.0", "10.10.2.255"); | ||
for (const x of cidr) { | ||
console.log(x); | ||
} | ||
cidr = tools.ipV6ToCIDR("2001:4860:4860:0000:0000:0000:0000:8888", "2001:4860:4860:0000:eeee:ffff:ffff:ffff"); | ||
for (const x of cidr) { | ||
console.log(x); | ||
} | ||
console.log(tools.cidrToIPV4("10.123.80.0/12")); | ||
console.log(tools.cidrToIPV6("2002:1234::abcd:ffff:c0a8:101/62")); | ||
``` | ||
## COUNTRY CLASS | ||
## Methods | ||
Below are the methods supported in this module. | ||
|Method Name|Description| | ||
|---|---| | ||
|Constructor(csvFile)|Expect a IP2Location Country Information CSV file. This database is free for download at https://www.ip2location.com/free/country-information| | ||
|getCountryInfo(countryCode)|Returns the country information.| | ||
## Usage | ||
```javascript | ||
const {Country} = require("ip2location-nodejs"); | ||
let country = new Country("./IP2LOCATION-COUNTRY-INFORMATION-BASIC.CSV"); | ||
country.getCountryInfo("US").then(country_info => { | ||
console.log(country_info); | ||
}); | ||
country.getCountryInfo("").then(country_info => { | ||
console.log(country_info); | ||
}); | ||
``` | ||
## REGION CLASS | ||
## Methods | ||
Below are the methods supported in this module. | ||
|Method Name|Description| | ||
|---|---| | ||
|Constructor(csvFile)|Expect a IP2Location ISO 3166-2 Subdivision Code CSV file. This database is free for download at https://www.ip2location.com/free/iso3166-2| | ||
|getRegionCode(countryCode, regionName)|Returns the region code for the supplied country code and region name.| | ||
## Usage | ||
```javascript | ||
const {Region} = require("ip2location-nodejs"); | ||
let region = new Region("./IP2LOCATION-ISO3166-2.CSV"); | ||
region.getRegionCode("US", "California").then(region_code => { | ||
console.log(region_code); | ||
}); | ||
``` | ||
## Developer Documentation | ||
To learn more about installation, usage, and code examples, please visit the developer documentation at [https://ip2location-nodejs.readthedocs.io/en/latest/index.html.](https://ip2location-nodejs.readthedocs.io/en/latest/index.html) |
@@ -11,2 +11,10 @@ export class IP2Location { | ||
/** | ||
* Reads bytes from file into buffer asynchronously. | ||
* | ||
* @param readBytes The number of bytes to read. | ||
* @param position The file offset to start reading. | ||
* @returns The promise of the buffer containing the read bytes. | ||
*/ | ||
readRowAsync(readBytes: number, position: number): Promise<any>; | ||
/** | ||
* Reads bytes from file and convert to specified data type. | ||
@@ -100,2 +108,9 @@ * | ||
/** | ||
* Reads string from file asynchronously. | ||
* | ||
* @param position The file offset to start reading. | ||
* @returns The promise of the string. | ||
*/ | ||
readStrAsync(position: number): Promise<string>; | ||
/** | ||
* Reads BIN file metadata. | ||
@@ -107,2 +122,8 @@ * | ||
/** | ||
* Reads BIN file metadata asynchronously. | ||
* | ||
* @returns The promise of whether metadata read successfully. | ||
*/ | ||
loadBinAsync(): Promise<boolean>; | ||
/** | ||
* Initializes with BIN file path and pre-loads metadata. | ||
@@ -114,2 +135,8 @@ * | ||
/** | ||
* Initializes with BIN file path and pre-loads metadata asynchronously. | ||
* | ||
* @param binPath The path to the BIN file. | ||
*/ | ||
openAsync(binPath: string): Promise<void>; | ||
/** | ||
* Resets metadata and closes file handle. | ||
@@ -130,2 +157,11 @@ * | ||
/** | ||
* Retrieves geolocation data into supplied object asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @param ipType 4 for IPv4 or 6 for IPv6. | ||
* @param data The object to store the results. | ||
* @param mode The fields to read. | ||
*/ | ||
geoQueryDataAsync(myIP: string, ipType: number, data: any, mode: any): Promise<void>; | ||
/** | ||
* Performs validations and returns geolocation data. | ||
@@ -167,2 +203,38 @@ * | ||
/** | ||
* Performs validations and returns geolocation data asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @param mode The fields to read. | ||
* @returns The promise of the geolocation data. | ||
*/ | ||
geoQueryAsync(myIP: string, mode: any): Promise<{ | ||
ip: string; | ||
ipNo: string; | ||
countryShort: string; | ||
countryLong: string; | ||
region: string; | ||
city: string; | ||
isp: string; | ||
domain: string; | ||
zipCode: string; | ||
latitude: string; | ||
longitude: string; | ||
timeZone: string; | ||
netSpeed: string; | ||
iddCode: string; | ||
areaCode: string; | ||
weatherStationCode: string; | ||
weatherStationName: string; | ||
mcc: string; | ||
mnc: string; | ||
mobileBrand: string; | ||
elevation: string; | ||
usageType: string; | ||
addressType: string; | ||
category: string; | ||
district: string; | ||
asn: string; | ||
as: string; | ||
}>; | ||
/** | ||
* Returns the API version. | ||
@@ -193,2 +265,9 @@ * | ||
/** | ||
* Returns the ISO 3166 country code asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the country code. | ||
*/ | ||
getCountryShortAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the country name. | ||
@@ -201,2 +280,9 @@ * | ||
/** | ||
* Returns the country name asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the country name. | ||
*/ | ||
getCountryLongAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the region or state. | ||
@@ -209,2 +295,9 @@ * | ||
/** | ||
* Returns the region or state asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the region or state. | ||
*/ | ||
getRegionAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the city. | ||
@@ -217,2 +310,9 @@ * | ||
/** | ||
* Returns the city asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the city. | ||
*/ | ||
getCityAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the Internet Service Provider. | ||
@@ -225,2 +325,9 @@ * | ||
/** | ||
* Returns the Internet Service Provider asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the ISP. | ||
*/ | ||
getISPAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the latitude. | ||
@@ -233,2 +340,9 @@ * | ||
/** | ||
* Returns the latitude asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the latitude. | ||
*/ | ||
getLatitudeAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the longitude. | ||
@@ -241,2 +355,9 @@ * | ||
/** | ||
* Returns the longitude asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the longitude. | ||
*/ | ||
getLongitudeAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the domain name. | ||
@@ -249,2 +370,9 @@ * | ||
/** | ||
* Returns the domain name asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the domain name. | ||
*/ | ||
getDomainAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the ZIP or postal code. | ||
@@ -257,2 +385,9 @@ * | ||
/** | ||
* Returns the ZIP or postal code asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the ZIP code. | ||
*/ | ||
getZIPCodeAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the time zone. | ||
@@ -265,2 +400,9 @@ * | ||
/** | ||
* Returns the time zone asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the time zone. | ||
*/ | ||
getTimeZoneAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the internet connection type. | ||
@@ -273,2 +415,9 @@ * | ||
/** | ||
* Returns the internet connection type asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the internet connection type. | ||
*/ | ||
getNetSpeedAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the IDD code. | ||
@@ -281,2 +430,9 @@ * | ||
/** | ||
* Returns the IDD code asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the IDD code. | ||
*/ | ||
getIDDCodeAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the area code. | ||
@@ -289,2 +445,9 @@ * | ||
/** | ||
* Returns the area code asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the area code. | ||
*/ | ||
getAreaCodeAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the weather station code. | ||
@@ -297,2 +460,9 @@ * | ||
/** | ||
* Returns the weather station code asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the weather station code. | ||
*/ | ||
getWeatherStationCodeAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the weather station name. | ||
@@ -305,2 +475,9 @@ * | ||
/** | ||
* Returns the weather station name asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the weather station name. | ||
*/ | ||
getWeatherStationNameAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the Mobile Country Code. | ||
@@ -313,2 +490,9 @@ * | ||
/** | ||
* Returns the Mobile Country Code asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the MCC. | ||
*/ | ||
getMCCAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the Mobile Network Code. | ||
@@ -321,2 +505,9 @@ * | ||
/** | ||
* Returns the Mobile Network Code asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the MNC. | ||
*/ | ||
getMNCAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the mobile brand. | ||
@@ -329,2 +520,9 @@ * | ||
/** | ||
* Returns the mobile brand asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the mobile brand. | ||
*/ | ||
getMobileBrandAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the elevation above sea level in meters. | ||
@@ -337,2 +535,9 @@ * | ||
/** | ||
* Returns the elevation above sea level in meters asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the elevation. | ||
*/ | ||
getElevationAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the usage type. | ||
@@ -345,2 +550,9 @@ * | ||
/** | ||
* Returns the usage type asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the usage type. | ||
*/ | ||
getUsageTypeAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the address type. | ||
@@ -353,2 +565,9 @@ * | ||
/** | ||
* Returns the address type asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the address type. | ||
*/ | ||
getAddressTypeAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the IAB category. | ||
@@ -361,2 +580,9 @@ * | ||
/** | ||
* Returns the IAB category asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the IAB category. | ||
*/ | ||
getCategoryAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the district name. | ||
@@ -369,2 +595,9 @@ * | ||
/** | ||
* Returns the district name asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the district name. | ||
*/ | ||
getDistrictAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the autonomous system number (ASN). | ||
@@ -377,2 +610,9 @@ * | ||
/** | ||
* Returns the autonomous system number (ASN) asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the ASN. | ||
*/ | ||
getASNAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns the autonomous system (AS). | ||
@@ -385,2 +625,9 @@ * | ||
/** | ||
* Returns the autonomous system (AS) asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of the AS. | ||
*/ | ||
getASAsync(myIP: string): Promise<string>; | ||
/** | ||
* Returns all fields. | ||
@@ -420,2 +667,37 @@ * | ||
}; | ||
/** | ||
* Returns all fields asynchronously. | ||
* | ||
* @param myIP The IP address to query. | ||
* @returns The promise of all geolocation fields. | ||
*/ | ||
getAllAsync(myIP: string): Promise<{ | ||
ip: string; | ||
ipNo: string; | ||
countryShort: string; | ||
countryLong: string; | ||
region: string; | ||
city: string; | ||
isp: string; | ||
domain: string; | ||
zipCode: string; | ||
latitude: string; | ||
longitude: string; | ||
timeZone: string; | ||
netSpeed: string; | ||
iddCode: string; | ||
areaCode: string; | ||
weatherStationCode: string; | ||
weatherStationName: string; | ||
mcc: string; | ||
mnc: string; | ||
mobileBrand: string; | ||
elevation: string; | ||
usageType: string; | ||
addressType: string; | ||
category: string; | ||
district: string; | ||
asn: string; | ||
as: string; | ||
}>; | ||
#private; | ||
@@ -422,0 +704,0 @@ } |
Sorry, the diff of this file is too big to display
106783
3110
29