Skip to content

Commit 17ebbeb

Browse files
committed
Added async functions
1 parent 9d86089 commit 17ebbeb

File tree

6 files changed

+854
-8
lines changed

6 files changed

+854
-8
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,41 @@ Below are the methods supported in this class.
3030
|Method Name|Description|
3131
|---|---|
3232
|open|Open the IP2Proxy BIN data for lookup.|
33+
|openAsync|Open the IP2Proxy BIN data for lookup asynchronously.|
3334
|close|Close and clean up the file pointer.|
3435
|getPackageVersion|Get the package version (1 to 11 for PX1 to PX11 respectively).|
3536
|getModuleVersion|Get the module version.|
3637
|getDatabaseVersion|Get the database version.|
3738
|isProxy|Check whether if an IP address was a proxy. Returned value:<ul><li>-1 : errors</li><li>0 : not a proxy</li><li>1 : a proxy</li><li>2 : a data center IP address or search engine robot</li></ul>|
39+
|isProxyAsync|Check whether if an IP address was a proxy asynchronously. Returned value:<ul><li>-1 : errors</li><li>0 : not a proxy</li><li>1 : a proxy</li><li>2 : a data center IP address or search engine robot</li></ul>|
3840
|getAll|Return the proxy information in an object.|
41+
|getAllAsync|Return the proxy information in an object asynchronously.|
3942
|getProxyType|Return the proxy type. Please visit <a href="https://www.ip2location.com/database/px10-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen-threat-residential" target="_blank">IP2Location</a> for the list of proxy types supported|
43+
|getProxyTypeAsync|Return the proxy type asynchronously. Please visit <a href="https://www.ip2location.com/database/px10-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen-threat-residential" target="_blank">IP2Location</a> for the list of proxy types supported|
4044
|getCountryShort|Return the ISO3166-1 country code (2-digits) of the proxy.|
45+
|getCountryShortAsync|Return the ISO3166-1 country code (2-digits) of the proxy asynchronously.|
4146
|getCountryLong|Return the ISO3166-1 country name of the proxy.|
47+
|getCountryLongAsync|Return the ISO3166-1 country name of the proxy asynchronously.|
4248
|getRegion|Return the ISO3166-2 region name of the proxy. Please visit <a href="https://www.ip2location.com/free/iso3166-2" target="_blank">ISO3166-2 Subdivision Code</a> for the information of ISO3166-2 supported|
49+
|getRegionAsync|Return the ISO3166-2 region name of the proxy asynchronously. Please visit <a href="https://www.ip2location.com/free/iso3166-2" target="_blank">ISO3166-2 Subdivision Code</a> for the information of ISO3166-2 supported|
4350
|getCity|Return the city name of the proxy.|
51+
|getCityAsync|Return the city name of the proxy asynchronously.|
4452
|getISP|Return the ISP name of the proxy.|
53+
|getISPAsync|Return the ISP name of the proxy asynchronously.|
4554
|getDomain|Return the domain name of the proxy.|
55+
|getDomainAsync|Return the domain name of the proxy asynchronously.|
4656
|getUsageType|Return the usage type classification of the proxy. Please visit <a href="https://www.ip2location.com/database/px10-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen-threat-residential" target="_blank">IP2Location</a> for the list of usage types supported.|
57+
|getUsageTypeAsync|Return the usage type classification of the proxy asynchronously. Please visit <a href="https://www.ip2location.com/database/px10-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen-threat-residential" target="_blank">IP2Location</a> for the list of usage types supported.|
4758
|getASN|Return the autonomous system number of the proxy.|
59+
|getASNAsync|Return the autonomous system number of the proxy asynchronously.|
4860
|getAS|Return the autonomous system name of the proxy.|
61+
|getASAsync|Return the autonomous system name of the proxy asynchronously.|
4962
|getLastSeen|Return the number of days that the proxy was last seen.|
63+
|getLastSeenAsync|Return the number of days that the proxy was last seen asynchronously.|
5064
|getThreat|Return the threat type of the proxy.|
65+
|getThreatAsync|Return the threat type of the proxy asynchronously.|
5166
|getProvider|Return the provider of the proxy.|
67+
|getProviderAsync|Return the provider of the proxy asynchronously.|
5268

5369
## Usage
5470

@@ -104,6 +120,40 @@ ip2proxy.close();
104120

105121
```
106122

123+
## Asynchronously Usage
124+
125+
```javascript
126+
const {IP2Proxy} = require("ip2proxy-nodejs");
127+
128+
let ip2proxy = new IP2Proxy();
129+
130+
ip2proxy.openAsync("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER.BIN").then((status) => {
131+
if (status == 0) {
132+
ip = '199.83.103.79';
133+
ip2proxy.getAllAsync(ip).then(all => {
134+
console.log("isProxy: " + all.isProxy);
135+
console.log("proxyType: " + all.proxyType);
136+
console.log("countryShort: " + all.countryShort);
137+
console.log("countryLong: " + all.countryLong);
138+
console.log("region: " + all.region);
139+
console.log("city: " + all.city);
140+
console.log("isp: " + all.isp);
141+
console.log("domain: " + all.domain);
142+
console.log("usagetype: " + all.usageType);
143+
console.log("asn: " + all.asn);
144+
console.log("as: " + all.as);
145+
console.log("lastSeen: " + all.lastSeen);
146+
console.log("threat: " + all.threat);
147+
console.log("provider: " + all.provider);
148+
});
149+
}
150+
else {
151+
console.log("Error reading BIN.");
152+
}
153+
});
154+
155+
```
156+
107157
## QUERY USING THE IP2PROXY PROXY DETECTION WEB SERVICE
108158

109159
## Methods

docs/source/code.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@ Construct the IP2Location Class.
88
```{py:function} open(binPath)
99
Load the IP2Proxy BIN database for lookup.
1010
11+
1112
:param str binPath: (Required) The file path links to IP2Proxy BIN databases.
1213
```
1314

15+
```{py:function} openAsync(binPath)
16+
Load the IP2Location BIN database for lookup asynchronously.
17+
18+
:param str binPath: (Required) The file path links to IP2Location BIN databases.
19+
```
20+
1421
```{py:function} getPackageVersion()
1522
Return the database's type, 1 to 10 respectively for PX1 to PX11. Please visit https://www.ip2location.com/databases/ip2proxy for details.
1623
@@ -41,6 +48,32 @@ Retrieve geolocation information for an IP address.
4148
4249
**RETURN FIELDS**
4350
51+
| Field Name | Description |
52+
| ---------------- | ------------------------------------------------------------ |
53+
| countryCode | Two-character country code based on ISO 3166. |
54+
| countryName | Country name based on ISO 3166. |
55+
| regionName | Region or state name. |
56+
| cityName | City name. |
57+
| isp | Internet Service Provider or company\'s name. |
58+
| domain | Internet domain name associated with IP address range. |
59+
| usageType | Usage type classification of ISP or company. |
60+
| asn | Autonomous system number (ASN). |
61+
| as | Autonomous system (AS) name. |
62+
| lastSeen | Proxy last seen in days. |
63+
| threat | Security threat reported. |
64+
| proxyType | Type of proxy. |
65+
| provider | Name of VPN provider if available. |
66+
```
67+
68+
```{py:function} getAllAsync(ipAddress)
69+
Retrieve geolocation information for an IP address asynchronously.
70+
71+
:param string ipAddress: (Required) The IP address (IPv4 or IPv6).
72+
:return: Returns the geolocation information in array. Refer below table for the fields avaliable in the array
73+
:rtype: Promise of an array
74+
75+
**RETURN FIELDS**
76+
4477
| Field Name | Description |
4578
| ---------------- | ------------------------------------------------------------ |
4679
| countryCode | Two-character country code based on ISO 3166. |

docs/source/quickstart.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,39 @@ else {
7373
console.log("Error reading BIN file.");
7474
}
7575
ip2proxy.close();
76-
```
76+
```
77+
78+
You can query the geolocation information asynchronously from the IP2Proxy BIN database as below:
79+
80+
```javascript
81+
const {IP2Proxy} = require("ip2proxy-nodejs");
82+
83+
let ip2proxy = new IP2Proxy();
84+
85+
ip2proxy.openAsync("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER.BIN").then((status) => {
86+
if (status == 0) {
87+
ip = '199.83.103.79';
88+
ip2proxy.getAllAsync(ip).then(all => {
89+
console.log("isProxy: " + all.isProxy);
90+
console.log("proxyType: " + all.proxyType);
91+
console.log("countryShort: " + all.countryShort);
92+
console.log("countryLong: " + all.countryLong);
93+
console.log("region: " + all.region);
94+
console.log("city: " + all.city);
95+
console.log("isp: " + all.isp);
96+
console.log("domain: " + all.domain);
97+
console.log("usagetype: " + all.usageType);
98+
console.log("asn: " + all.asn);
99+
console.log("as: " + all.as);
100+
console.log("lastSeen: " + all.lastSeen);
101+
console.log("threat: " + all.threat);
102+
console.log("provider: " + all.provider);
103+
});
104+
}
105+
else {
106+
console.log("Error reading BIN.");
107+
}
108+
});
109+
110+
```
111+

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ip2proxy-nodejs",
3-
"version": "4.2.3",
3+
"version": "4.3.0",
44
"description": "IP2Proxy proxy detection component",
55
"keywords": [
66
"vpn-detection",
@@ -29,7 +29,7 @@
2929
"license": "MIT",
3030
"repository": {
3131
"type": "git",
32-
"url": "https://github.com/ip2location/ip2proxy-nodejs"
32+
"url": "git+https://github.com/ip2location/ip2proxy-nodejs.git"
3333
},
3434
"devDependencies": {
3535
"prettier": "2.4.0"

0 commit comments

Comments
 (0)