Skip to content

Commit 850eac5

Browse files
committed
Added support for PX5 to PX8 packages
1 parent d78bdcc commit 850eac5

File tree

4 files changed

+125
-20
lines changed

4 files changed

+125
-20
lines changed

LICENSE.TXT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 IP2Location.com
3+
Copyright (c) 2019 IP2Location.com
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# IP2Proxy Erlang Module
22

3-
This module allows user to query an IP address if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits. It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
3+
This module allows user to query an IP address if it was being used as VPN anonymizer, open proxies, web proxies, Tor exits, data center, web hosting (DCH) range and search engine robots (SES). It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
44

5-
* Free IP2Proxy BIN Data: http://lite.ip2location.com
6-
* Commercial IP2Proxy BIN Data: http://www.ip2location.com/proxy-database
5+
* Free IP2Proxy BIN Data: https://lite.ip2location.com
6+
* Commercial IP2Proxy BIN Data: https://www.ip2location.com/database/ip2proxy
77

88

99
## Compilation
@@ -19,17 +19,22 @@ Below are the methods supported in this package.
1919
|---|---|
2020
|open|Open the IP2Proxy BIN data for lookup.|
2121
|close|Close and clean up metadata.|
22-
|getpackageversion|Get the package version (1 to 4 for PX1 to PX4 respectively).|
22+
|getpackageversion|Get the package version (1 to 8 for PX1 to PX8 respectively).|
2323
|getmoduleversion|Get the module version.|
2424
|getdatabaseversion|Get the database version.|
25-
|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</li></ul>|
25+
|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>|
2626
|getall|Return the proxy information in an array.|
27-
|getproxytype|Return the proxy type. Please visit <a href="https://www.ip2location.com/databases/px4-ip-proxytype-country-region-city-isp" target="_blank">IP2Location</a> for the list of proxy types supported|
27+
|getproxytype|Return the proxy type. Please visit <a href="https://www.ip2location.com/database/px8-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen" target="_blank">IP2Location</a> for the list of proxy types supported.|
2828
|getcountryshort|Return the ISO3166-1 country code (2-digits) of the proxy.|
2929
|getcountrylong|Return the ISO3166-1 country name of the proxy.|
30-
|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|
30+
|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.|
3131
|getcity|Return the city name of the proxy.|
3232
|getisp|Return the ISP name of the proxy.|
33+
|getdomain|Return the domain name of the proxy.|
34+
|getusagetype|Return the usage type classification of the proxy. Please visit <a href="https://www.ip2location.com/database/px8-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen" target="_blank">IP2Location</a> for the list of usage types supported.|
35+
|getasn|Return the autonomous system number of the proxy.|
36+
|getas|Return the autonomous system name of the proxy.|
37+
|getlastseen|Return the number of days that the proxy was last seen.|
3338

3439
## Example
3540

ip2proxy.erl

Lines changed: 99 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
-module(ip2proxy).
2-
-export([getpackageversion/0, getmoduleversion/0, getdatabaseversion/0, open/1, getall/1, getproxytype/1, getcountryshort/1, getcountrylong/1, getregion/1, getcity/1, getisp/1, isproxy/1, close/0]).
2+
-export([getpackageversion/0, getmoduleversion/0, getdatabaseversion/0, open/1, getall/1, getproxytype/1, getcountryshort/1, getcountrylong/1, getregion/1, getcity/1, getisp/1, getdomain/1, getusagetype/1, getasn/1, getas/1, getlastseen/1, isproxy/1, close/0]).
33
-record(ip2proxyrecord, {
44
country_short = "-",
55
country_long = "-",
66
region = "-",
77
city = "-",
88
isp = "-",
99
proxy_type = "-",
10+
domain = "-",
11+
usage_type = "-",
12+
asn = "-",
13+
as = "-",
14+
last_seen = "-",
1015
is_proxy = 0
1116
}).
1217

@@ -26,7 +31,7 @@ getpackageversion() ->
2631
end.
2732

2833
getmoduleversion() ->
29-
"1.0.0".
34+
"2.0.0".
3035

3136
getdatabaseversion() ->
3237
case ets:info(mymeta) of
@@ -152,11 +157,16 @@ readcolstring(S, Dbtype, Rowoffset, Col) ->
152157

153158

154159
readrecord(S, Dbtype, Rowoffset, Mode) ->
155-
Country_position = [0, 2, 3, 3, 3],
156-
Region_position = [0, 0, 0, 4, 4],
157-
City_position = [0, 0, 0, 5, 5],
158-
Isp_position = [0, 0, 0, 0, 6],
159-
Proxytype_position = [0, 0, 2, 2, 2],
160+
Country_position = [0, 2, 3, 3, 3, 3, 3, 3, 3],
161+
Region_position = [0, 0, 0, 4, 4, 4, 4, 4, 4],
162+
City_position = [0, 0, 0, 5, 5, 5, 5, 5, 5],
163+
Isp_position = [0, 0, 0, 0, 6, 6, 6, 6, 6],
164+
Proxytype_position = [0, 0, 2, 2, 2, 2, 2, 2, 2],
165+
Domain_position = [0, 0, 0, 0, 0, 7, 7, 7, 7],
166+
Usagetype_position = [0, 0, 0, 0, 0, 0, 8, 8, 8],
167+
Asn_position = [0, 0, 0, 0, 0, 0, 0, 9, 9],
168+
As_position = [0, 0, 0, 0, 0, 0, 0, 10, 10],
169+
Lastseen_position = [0, 0, 0, 0, 0, 0, 0, 0, 11],
160170

161171
Countryshort_field = 1,
162172
Countrylong_field = 2,
@@ -165,6 +175,11 @@ readrecord(S, Dbtype, Rowoffset, Mode) ->
165175
Isp_field = 16,
166176
Proxytype_field = 32,
167177
Isproxy_field = 64,
178+
Domain_field = 128,
179+
Usagetype_field = 256,
180+
Asn_field = 512,
181+
As_field = 1024,
182+
Lastseen_field = 2048,
168183

169184
if
170185
(Mode band Proxytype_field /= 0) or (Mode band Isproxy_field /= 0) ->
@@ -201,12 +216,47 @@ readrecord(S, Dbtype, Rowoffset, Mode) ->
201216
Isp = ""
202217
end,
203218

219+
if
220+
Mode band Domain_field /= 0 ->
221+
Domain = readcolstring(S, Dbtype, Rowoffset, Domain_position);
222+
true ->
223+
Domain = ""
224+
end,
225+
226+
if
227+
Mode band Usagetype_field /= 0 ->
228+
Usage_type = readcolstring(S, Dbtype, Rowoffset, Usagetype_position);
229+
true ->
230+
Usage_type = ""
231+
end,
232+
233+
if
234+
Mode band Asn_field /= 0 ->
235+
Asn = readcolstring(S, Dbtype, Rowoffset, Asn_position);
236+
true ->
237+
Asn = ""
238+
end,
239+
240+
if
241+
Mode band As_field /= 0 ->
242+
As = readcolstring(S, Dbtype, Rowoffset, As_position);
243+
true ->
244+
As = ""
245+
end,
246+
247+
if
248+
Mode band Lastseen_field /= 0 ->
249+
Last_seen = readcolstring(S, Dbtype, Rowoffset, Lastseen_position);
250+
true ->
251+
Last_seen = ""
252+
end,
253+
204254
if
205255
(Country_short == "-") or (Proxy_type == "-") ->
206256
Is_proxy = 0;
207257
true ->
208258
if
209-
Proxy_type == "DCH" ->
259+
(Proxy_type == "DCH") or (Proxy_type == "SES") ->
210260
Is_proxy = 2;
211261
true ->
212262
Is_proxy = 1
@@ -220,6 +270,11 @@ readrecord(S, Dbtype, Rowoffset, Mode) ->
220270
city = City,
221271
isp = Isp,
222272
proxy_type = Proxy_type,
273+
domain = Domain,
274+
usage_type = Usage_type,
275+
asn = Asn,
276+
as = As,
277+
last_seen = Last_seen,
223278
is_proxy = Is_proxy
224279
}.
225280

@@ -265,6 +320,11 @@ searchtree(S, Ipnum, Dbtype, Low, High, BaseAddr, Colsize, Iptype, Mode) ->
265320
city = X,
266321
isp = X,
267322
proxy_type = X,
323+
domain = X,
324+
usage_type = X,
325+
asn = X,
326+
as = X,
327+
last_seen = X,
268328
is_proxy = -1
269329
}
270330
end.
@@ -292,7 +352,7 @@ search6(S, Ipnum, Dbtype, Low, High, Baseaddr, Indexbaseaddr, Colsize, Mode) ->
292352
end.
293353

294354
getall(Ip) ->
295-
query(Ip, 127).
355+
query(Ip, 4095).
296356

297357
getcountryshort(Ip) ->
298358
Result = query(Ip, 1),
@@ -318,6 +378,26 @@ getproxytype(Ip) ->
318378
Result = query(Ip, 32),
319379
Result#ip2proxyrecord.proxy_type.
320380

381+
getdomain(Ip) ->
382+
Result = query(Ip, 128),
383+
Result#ip2proxyrecord.domain.
384+
385+
getusagetype(Ip) ->
386+
Result = query(Ip, 256),
387+
Result#ip2proxyrecord.usage_type.
388+
389+
getasn(Ip) ->
390+
Result = query(Ip, 512),
391+
Result#ip2proxyrecord.asn.
392+
393+
getas(Ip) ->
394+
Result = query(Ip, 1024),
395+
Result#ip2proxyrecord.as.
396+
397+
getlastseen(Ip) ->
398+
Result = query(Ip, 2048),
399+
Result#ip2proxyrecord.last_seen.
400+
321401
isproxy(Ip) ->
322402
Result = query(Ip, 64),
323403
Result#ip2proxyrecord.is_proxy.
@@ -374,6 +454,11 @@ query(Ip, Mode) ->
374454
city = X,
375455
isp = X,
376456
proxy_type = X,
457+
domain = X,
458+
usage_type = X,
459+
asn = X,
460+
as = X,
461+
last_seen = X,
377462
is_proxy = -1
378463
}
379464
end;
@@ -385,6 +470,11 @@ query(Ip, Mode) ->
385470
city = Y,
386471
isp = Y,
387472
proxy_type = Y,
473+
domain = Y,
474+
usage_type = Y,
475+
asn = Y,
476+
as = Y,
477+
last_seen = Y,
388478
is_proxy = -1
389479
}
390480
end

test.erl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,25 @@ printme(V) ->
55
case V of
66
{} ->
77
io:format("No results.~n", []);
8-
{ip2proxyrecord, Country_short, Country_long, Region, City, Isp, Proxy_type, Is_proxy} ->
8+
{ip2proxyrecord, Country_short, Country_long, Region, City, Isp, Proxy_type, Domain, Usage_type, Asn, As, Last_seen, Is_proxy} ->
99
io:format("Country_short: ~p~n", [Country_short]),
1010
io:format("Country_long: ~p~n", [Country_long]),
1111
io:format("Region: ~p~n", [Region]),
1212
io:format("City: ~p~n", [City]),
1313
io:format("Isp: ~p~n", [Isp]),
1414
io:format("Proxy_type: ~p~n", [Proxy_type]),
15+
io:format("Domain: ~p~n", [Domain]),
16+
io:format("Usage_type: ~p~n", [Usage_type]),
17+
io:format("Asn: ~p~n", [Asn]),
18+
io:format("As: ~p~n", [As]),
19+
io:format("Last_seen: ~p~n", [Last_seen]),
1520
io:format("Is_proxy: ~p~n", [Is_proxy])
1621
end,
1722
io:format("===================================================================~n", []).
1823

1924
testme() ->
20-
X = "199.83.103.79",
21-
case ip2proxy:open("IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.BIN") of
25+
X = "37.252.228.50",
26+
case ip2proxy:open("./IP2Proxy/bin/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN.BIN") of
2227
0 ->
2328
io:format("getpackageversion: ~p~n", [ip2proxy:getpackageversion()]),
2429
io:format("getmoduleversion: ~p~n", [ip2proxy:getmoduleversion()]),
@@ -32,6 +37,11 @@ testme() ->
3237
io:format("City: ~p~n", [ip2proxy:getcity(X)]),
3338
io:format("Isp: ~p~n", [ip2proxy:getisp(X)]),
3439
io:format("Proxy_type: ~p~n", [ip2proxy:getproxytype(X)]),
40+
io:format("Domain: ~p~n", [ip2proxy:getdomain(X)]),
41+
io:format("Usage_type: ~p~n", [ip2proxy:getusagetype(X)]),
42+
io:format("Asn: ~p~n", [ip2proxy:getasn(X)]),
43+
io:format("AS: ~p~n", [ip2proxy:getas(X)]),
44+
io:format("Last_seen: ~p~n", [ip2proxy:getlastseen(X)]),
3545
io:format("Is_proxy: ~p~n", [ip2proxy:isproxy(X)]);
3646
_ ->
3747
io:format("Error reading BIN file~n", [])

0 commit comments

Comments
 (0)