Skip to content

Commit ea62833

Browse files
committed
Modified to be classes. Added support for IP2Location Web Service.
1 parent d82b87c commit ea62833

File tree

4 files changed

+1271
-768
lines changed

4 files changed

+1271
-768
lines changed

README.md

Lines changed: 80 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ The database will be updated on a monthly basis for greater accuracy.
2020
The complete database is available at https://www.ip2location.com under Premium subscription package.
2121
The free LITE database is available at https://lite.ip2location.com.
2222

23+
As an alternative, this module can also call the IP2Location Web Service. This requires an API key. If you don't have an existing API key, you can subscribe for one at the below:
24+
25+
https://www.ip2location.com/web-service/ip2location
2326

2427
## Installation
2528

@@ -31,6 +34,7 @@ npm install ip2location-nodejs
3134

3235
```
3336

37+
## QUERY USING THE BIN FILE
3438

3539
## Dependencies
3640

@@ -53,50 +57,97 @@ Below are the methods supported in this module.
5357

5458
|Method Name|Description|
5559
|---|---|
56-
|IP2Location_init|Opens the IP2Location BIN data for lookup.|
57-
|IP2Location_get_all|Returns the geolocation information in an object.|
58-
|IP2Location_get_country_short|Returns the country code.|
59-
|IP2Location_get_country_long|Returns the country name.|
60-
|IP2Location_get_region|Returns the region name.|
61-
|IP2Location_get_city|Returns the city name.|
62-
|IP2Location_get_isp|Returns the ISP name.|
63-
|IP2Location_get_latitude|Returns the latitude.|
64-
|IP2Location_get_longitude|Returns the longitude.|
65-
|IP2Location_get_domain|Returns the domain name.|
66-
|IP2Location_get_zipcode|Returns the ZIP code.|
67-
|IP2Location_get_timezone|Returns the time zone.|
68-
|IP2Location_get_netspeed|Returns the net speed.|
69-
|IP2Location_get_iddcode|Returns the IDD code.|
70-
|IP2Location_get_areacode|Returns the area code.|
71-
|IP2Location_get_weatherstationcode|Returns the weather station code.|
72-
|IP2Location_get_weatherstationname|Returns the weather station name.|
73-
|IP2Location_get_mcc|Returns the mobile country code.|
74-
|IP2Location_get_mnc|Returns the mobile network code.|
75-
|IP2Location_get_mobilebrand|Returns the mobile brand.|
76-
|IP2Location_get_elevation|Returns the elevation in meters.|
77-
|IP2Location_get_usagetype|Returns the usage type.|
78-
|IP2Location_get_addresstype|Returns the address type.|
79-
|IP2Location_get_category|Returns the IAB category.|
80-
|IP2Location_close|Closes BIN file and resets metadata.|
60+
|open|Opens the IP2Location BIN data for lookup.|
61+
|getAll|Returns the geolocation information in an object.|
62+
|getCountryShort|Returns the country code.|
63+
|getCountryLong|Returns the country name.|
64+
|getRegion|Returns the region name.|
65+
|getCity|Returns the city name.|
66+
|getISP|Returns the ISP name.|
67+
|getLatitude|Returns the latitude.|
68+
|getLongitude|Returns the longitude.|
69+
|getDomain|Returns the domain name.|
70+
|getZIPCode|Returns the ZIP code.|
71+
|getTimeZone|Returns the time zone.|
72+
|getNetSpeed|Returns the net speed.|
73+
|getIDDCode|Returns the IDD code.|
74+
|getAreaCode|Returns the area code.|
75+
|getWeatherStationCode|Returns the weather station code.|
76+
|getWeatherStationName|Returns the weather station name.|
77+
|getMCC|Returns the mobile country code.|
78+
|getMNC|Returns the mobile network code.|
79+
|getMobileBrand|Returns the mobile brand.|
80+
|getElevation|Returns the elevation in meters.|
81+
|getUsageType|Returns the usage type.|
82+
|getAddressType|Returns the address type.|
83+
|getCategory|Returns the IAB category.|
84+
|close|Closes BIN file and resets metadata.|
8185

8286

8387
## Usage
8488

8589
```javascript
8690

87-
var ip2loc = require("ip2location-nodejs");
91+
const {IP2Location} = require("ip2location-nodejs");
92+
93+
let ip2location = new IP2Location();
8894

89-
ip2loc.IP2Location_init("./DB25.BIN");
95+
ip2location.open("./DB25.BIN");
9096

9197
testip = ['8.8.8.8', '2404:6800:4001:c01::67'];
9298

9399
for (var x = 0; x < testip.length; x++) {
94-
result = ip2loc.IP2Location_get_all(testip[x]);
100+
result = ip2location.getAll(testip[x]);
95101
for (var key in result) {
96102
console.log(key + ": " + result[key]);
97103
}
98104
console.log("--------------------------------------------------------------");
99105
}
100106

101-
ip2loc.IP2Location_close();
107+
ip2location.close();
108+
102109
```
110+
111+
## QUERY USING THE IP2PROXY PROXY DETECTION WEB SERVICE
112+
113+
## Methods
114+
Below are the methods supported in this module.
115+
116+
|Method Name|Description|
117+
|---|---|
118+
|open| 3 input parameters:<ol><li>IP2Location API Key.</li><li>Package (WS1 - WS25)</li></li><li>Use HTTPS or HTTP</li></ol> |
119+
|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>|
120+
|getCredit()|This method returns the web service credit balance in an object.|
121+
122+
## Usage
123+
124+
```javascript
125+
126+
const {IP2LocationWebService} = require("ip2location-nodejs");
127+
128+
let ws = new IP2LocationWebService();
129+
130+
let ip = "8.8.8.8";
131+
let apiKey = "YOUR_API_KEY";
132+
let apiPackage = "WS25";
133+
let useSSL = true;
134+
135+
// addon and lang to get more data and translation (leave both blank if you don't need them)
136+
let addon = "continent,country,region,city,geotargeting,country_groupings,time_zone_info";
137+
let lang = "fr";
138+
139+
ws.open(apiKey, apiPackage, useSSL);
140+
141+
ws.lookup(ip, addon, lang, (err, data) => {
142+
if (!err) {
143+
console.log(data);
144+
145+
ws.getCredit((err, data) => {
146+
if (!err) {
147+
console.log(data);
148+
}
149+
});
150+
}
151+
});
152+
153+
```

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ip2location-nodejs",
3-
"version": "8.5.0",
3+
"version": "9.0.0",
44
"description": "IP2Location geolocation component",
55
"keywords": [
66
"ip2location",
@@ -25,5 +25,8 @@
2525
"repository": {
2626
"type": "git",
2727
"url": "https://github.com/ip2location/ip2location-nodejs.git"
28+
},
29+
"devDependencies": {
30+
"prettier": "2.4.0"
2831
}
2932
}

0 commit comments

Comments
 (0)