Skip to content

Commit e3deab6

Browse files
committed
Modified to be classes. Added support for IP2Proxy Web Service.
1 parent 983bece commit e3deab6

File tree

4 files changed

+1023
-725
lines changed

4 files changed

+1023
-725
lines changed

README.md

Lines changed: 102 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ This module allows user to query an IP address if it was being used as VPN anony
88
* Free IP2Proxy BIN Data: https://lite.ip2location.com
99
* Commercial IP2Proxy BIN Data: https://www.ip2location.com/database/ip2proxy
1010

11+
As an alternative, this module can also call the IP2Proxy Web Service. This requires an API key. If you don't have an existing API key, you can subscribe for one at the below:
12+
13+
https://www.ip2location.com/web-service/ip2proxy
1114

1215
## Installation
1316

@@ -19,13 +22,15 @@ npm install ip2proxy-nodejs
1922

2023
```
2124

25+
## QUERY USING THE BIN FILE
26+
2227
## Methods
2328
Below are the methods supported in this class.
2429

2530
|Method Name|Description|
2631
|---|---|
27-
|Open|Open the IP2Proxy BIN data for lookup.|
28-
|Close|Close and clean up the file pointer.|
32+
|open|Open the IP2Proxy BIN data for lookup.|
33+
|close|Close and clean up the file pointer.|
2934
|getPackageVersion|Get the package version (1 to 11 for PX1 to PX11 respectively).|
3035
|getModuleVersion|Get the module version.|
3136
|getDatabaseVersion|Get the database version.|
@@ -48,10 +53,11 @@ Below are the methods supported in this class.
4853
## Usage
4954

5055
```javascript
56+
const {IP2Proxy} = require("ip2proxy-nodejs");
5157

52-
var ip2proxy = require("ip2proxy-nodejs");
58+
let ip2proxy = new IP2Proxy();
5359

54-
if (ip2proxy.Open("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER.BIN") == 0) {
60+
if (ip2proxy.open("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER.BIN") == 0) {
5561
ip = '199.83.103.79';
5662

5763
console.log("GetModuleVersion: " + ip2proxy.getModuleVersion());
@@ -75,25 +81,101 @@ if (ip2proxy.Open("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGET
7581
console.log("Provider: " + ip2proxy.getProvider(ip));
7682

7783
// function for all fields
78-
var all = ip2proxy.getAll(ip);
79-
console.log("isProxy: " + all.Is_Proxy);
80-
console.log("ProxyType: " + all.Proxy_Type);
81-
console.log("CountryShort: " + all.Country_Short);
82-
console.log("CountryLong: " + all.Country_Long);
83-
console.log("Region: " + all.Region);
84-
console.log("City: " + all.City);
85-
console.log("ISP: " + all.ISP);
86-
console.log("Domain: " + all.Domain);
87-
console.log("UsageType: " + all.Usage_Type);
88-
console.log("ASN: " + all.ASN);
89-
console.log("AS: " + all.AS);
90-
console.log("LastSeen: " + all.Last_Seen);
91-
console.log("Threat: " + all.Threat);
92-
console.log("Provider: " + all.Provider);
84+
let all = ip2proxy.getAll(ip);
85+
console.log("isProxy: " + all.isProxy);
86+
console.log("proxyType: " + all.proxyType);
87+
console.log("countryShort: " + all.countryShort);
88+
console.log("countryLong: " + all.countryLong);
89+
console.log("region: " + all.region);
90+
console.log("city: " + all.city);
91+
console.log("isp: " + all.isp);
92+
console.log("domain: " + all.domain);
93+
console.log("usagetype: " + all.usageType);
94+
console.log("asn: " + all.asn);
95+
console.log("as: " + all.as);
96+
console.log("lastSeen: " + all.lastSeen);
97+
console.log("threat: " + all.threat);
98+
console.log("provider: " + all.provider);
9399
}
94100
else {
95101
console.log("Error reading BIN file.");
96102
}
97-
ip2proxy.Close();
103+
ip2proxy.close();
104+
105+
```
106+
107+
## QUERY USING THE IP2PROXY PROXY DETECTION WEB SERVICE
108+
109+
## Methods
110+
Below are the methods supported in this class.
111+
112+
|Method Name|Description|
113+
|---|---|
114+
|open(apiKey, apiPackage, useSSL = true)| Expects 2 or 3 input parameters:<ol><li>IP2Proxy API Key.</li><li>Package (PX1 - PX11)</li></li><li>Use HTTPS or HTTP</li></ol> |
115+
|lookup(myIP, callback)|Query IP address. This method returns an object containing the proxy info. <ul><li>countryCode</li><li>countryName</li><li>regionName</li><li>cityName</li><li>isp</li><li>domain</li><li>usageType</li><li>asn</li><li>as</li><li>lastSeen</li><li>threat</li><li>proxyType</li><li>isProxy</li><li>provider</li><ul>|
116+
|getCredit()|This method returns the web service credit balance in an object.|
117+
118+
## Usage
119+
120+
```javascript
121+
const {IP2ProxyWebService} = require("ip2proxy-nodejs");
122+
123+
let ws = new IP2ProxyWebService();
124+
125+
let ip = "8.8.8.8";
126+
let apiKey = "YOUR_API_KEY";
127+
let apiPackage = "PX11";
128+
let useSSL = true;
129+
130+
ws.open(apiKey, apiPackage, useSSL);
131+
132+
ws.lookup(ip, (err, data) => {
133+
if (!err) {
134+
console.log(data);
135+
136+
ws.getCredit((err, data) => {
137+
if (!err) {
138+
console.log(data);
139+
}
140+
});
141+
}
142+
});
98143

99144
```
145+
146+
### Proxy Type
147+
148+
|Proxy Type|Description|
149+
|---|---|
150+
|VPN|Anonymizing VPN services|
151+
|TOR|Tor Exit Nodes|
152+
|PUB|Public Proxies|
153+
|WEB|Web Proxies|
154+
|DCH|Hosting Providers/Data Center|
155+
|SES|Search Engine Robots|
156+
|RES|Residential Proxies [PX10+]|
157+
158+
### Usage Type
159+
160+
|Usage Type|Description|
161+
|---|---|
162+
|COM|Commercial|
163+
|ORG|Organization|
164+
|GOV|Government|
165+
|MIL|Military|
166+
|EDU|University/College/School|
167+
|LIB|Library|
168+
|CDN|Content Delivery Network|
169+
|ISP|Fixed Line ISP|
170+
|MOB|Mobile ISP|
171+
|DCH|Data Center/Web Hosting/Transit|
172+
|SES|Search Engine Spider|
173+
|RSV|Reserved|
174+
175+
### Threat Type
176+
177+
|Threat Type|Description|
178+
|---|---|
179+
|SPAM|Spammer|
180+
|SCANNER|Security Scanner or Attack|
181+
|BOTNET|Spyware or Malware|

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ip2proxy-nodejs",
3-
"version": "3.1.0",
3+
"version": "4.0.0",
44
"description": "IP2Proxy proxy detection component",
55
"keywords": [
66
"vpn-detection",
@@ -31,5 +31,8 @@
3131
"repository": {
3232
"type": "git",
3333
"url": "https://github.com/ip2location/ip2proxy-nodejs"
34+
},
35+
"devDependencies": {
36+
"prettier": "2.4.0"
3437
}
3538
}

0 commit comments

Comments
 (0)