Skip to content

Commit 416eb79

Browse files
committed
Added support for threats (PX9) & residential proxies (PX10)
1 parent c9b2453 commit 416eb79

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
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) 2019 IP2Location.com
3+
Copyright (c) 2020 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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# IP2Proxy Erlang Module
22

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
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, search engine robots (SES) and residential (RES). It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
44

55
* Free IP2Proxy BIN Data: https://lite.ip2location.com
66
* Commercial IP2Proxy BIN Data: https://www.ip2location.com/database/ip2proxy
@@ -19,22 +19,23 @@ 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 8 for PX1 to PX8 respectively).|
22+
|getpackageversion|Get the package version (1 to 10 for PX1 to PX10 respectively).|
2323
|getmoduleversion|Get the module version.|
2424
|getdatabaseversion|Get the database version.|
2525
|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/database/px8-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen" 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/px10-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen-threat-residential" 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.|
3030
|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.|
3333
|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.|
34+
|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.|
3535
|getasn|Return the autonomous system number of the proxy.|
3636
|getas|Return the autonomous system name of the proxy.|
3737
|getlastseen|Return the number of days that the proxy was last seen.|
38+
|getthreat|Return the threat type of the proxy.|
3839

3940
## Example
4041

ip2proxy.erl

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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, getdomain/1, getusagetype/1, getasn/1, getas/1, getlastseen/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, getthreat/1, isproxy/1, close/0]).
33
-record(ip2proxyrecord, {
44
country_short = "-",
55
country_long = "-",
@@ -12,6 +12,7 @@
1212
asn = "-",
1313
as = "-",
1414
last_seen = "-",
15+
threat = "-",
1516
is_proxy = 0
1617
}).
1718
-define(IF(Cond), (case (Cond) of true -> (0); false -> (1) end)).
@@ -32,7 +33,7 @@ getpackageversion() ->
3233
end.
3334

3435
getmoduleversion() ->
35-
"2.2.0".
36+
"3.0.0".
3637

3738
getdatabaseversion() ->
3839
case ets:info(mymeta) of
@@ -186,16 +187,17 @@ readcolstringrow(S, R, Dbtype, Col) ->
186187
end.
187188

188189
readrecord(S, Dbtype, Rowoffset, Mode) ->
189-
Country_position = [0, 2, 3, 3, 3, 3, 3, 3, 3],
190-
Region_position = [0, 0, 0, 4, 4, 4, 4, 4, 4],
191-
City_position = [0, 0, 0, 5, 5, 5, 5, 5, 5],
192-
Isp_position = [0, 0, 0, 0, 6, 6, 6, 6, 6],
193-
Proxytype_position = [0, 0, 2, 2, 2, 2, 2, 2, 2],
194-
Domain_position = [0, 0, 0, 0, 0, 7, 7, 7, 7],
195-
Usagetype_position = [0, 0, 0, 0, 0, 0, 8, 8, 8],
196-
Asn_position = [0, 0, 0, 0, 0, 0, 0, 9, 9],
197-
As_position = [0, 0, 0, 0, 0, 0, 0, 10, 10],
198-
Lastseen_position = [0, 0, 0, 0, 0, 0, 0, 0, 11],
190+
Country_position = [0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3],
191+
Region_position = [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4],
192+
City_position = [0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5],
193+
Isp_position = [0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6],
194+
Proxytype_position = [0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2],
195+
Domain_position = [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7],
196+
Usagetype_position = [0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8],
197+
Asn_position = [0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9],
198+
As_position = [0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10],
199+
Lastseen_position = [0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11],
200+
Threat_position = [0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12],
199201

200202
Countryshort_field = 1,
201203
Countrylong_field = 2,
@@ -209,8 +211,9 @@ readrecord(S, Dbtype, Rowoffset, Mode) ->
209211
Asn_field = 512,
210212
As_field = 1024,
211213
Lastseen_field = 2048,
214+
Threat_field = 4096,
212215

213-
Cols = ?IF(lists:nth(Dbtype, Country_position) == 0) + ?IF(lists:nth(Dbtype, Region_position) == 0) + ?IF(lists:nth(Dbtype, City_position) == 0) + ?IF(lists:nth(Dbtype, Isp_position) == 0) + ?IF(lists:nth(Dbtype, Proxytype_position) == 0) + ?IF(lists:nth(Dbtype, Domain_position) == 0) + ?IF(lists:nth(Dbtype, Usagetype_position) == 0) + ?IF(lists:nth(Dbtype, Asn_position) == 0) + ?IF(lists:nth(Dbtype, As_position) == 0) + ?IF(lists:nth(Dbtype, Lastseen_position) == 0),
216+
Cols = ?IF(lists:nth(Dbtype, Country_position) == 0) + ?IF(lists:nth(Dbtype, Region_position) == 0) + ?IF(lists:nth(Dbtype, City_position) == 0) + ?IF(lists:nth(Dbtype, Isp_position) == 0) + ?IF(lists:nth(Dbtype, Proxytype_position) == 0) + ?IF(lists:nth(Dbtype, Domain_position) == 0) + ?IF(lists:nth(Dbtype, Usagetype_position) == 0) + ?IF(lists:nth(Dbtype, Asn_position) == 0) + ?IF(lists:nth(Dbtype, As_position) == 0) + ?IF(lists:nth(Dbtype, Lastseen_position) == 0) + ?IF(lists:nth(Dbtype, Threat_position) == 0),
214217
Rowlength = Cols bsl 2,
215218

216219
case file:pread(S, Rowoffset - 1, Rowlength) of
@@ -299,6 +302,14 @@ readrecord(S, Dbtype, Rowoffset, Mode) ->
299302
Last_seen = ""
300303
end,
301304

305+
if
306+
Mode band Threat_field /= 0 ->
307+
% Threat = readcolstring(S, Dbtype, Rowoffset, Threat_position);
308+
Threat = readcolstringrow(S, R, Dbtype, Threat_position);
309+
true ->
310+
Threat = ""
311+
end,
312+
302313
if
303314
(Country_short == "-") or (Proxy_type == "-") ->
304315
Is_proxy = 0;
@@ -323,6 +334,7 @@ readrecord(S, Dbtype, Rowoffset, Mode) ->
323334
asn = Asn,
324335
as = As,
325336
last_seen = Last_seen,
337+
threat = Threat,
326338
is_proxy = Is_proxy
327339
}
328340
end.
@@ -376,6 +388,7 @@ searchtree(S, Ipnum, Dbtype, Low, High, BaseAddr, Colsize, Iptype, Mode) ->
376388
asn = X,
377389
as = X,
378390
last_seen = X,
391+
threat = X,
379392
is_proxy = -1
380393
}
381394
end.
@@ -403,7 +416,7 @@ search6(S, Ipnum, Dbtype, Low, High, Baseaddr, Indexbaseaddr, Colsize, Mode) ->
403416
end.
404417

405418
getall(Ip) ->
406-
query(Ip, 4095).
419+
query(Ip, 8191).
407420

408421
getcountryshort(Ip) ->
409422
Result = query(Ip, 1),
@@ -449,6 +462,10 @@ getlastseen(Ip) ->
449462
Result = query(Ip, 2048),
450463
Result#ip2proxyrecord.last_seen.
451464

465+
getthreat(Ip) ->
466+
Result = query(Ip, 4096),
467+
Result#ip2proxyrecord.threat.
468+
452469
isproxy(Ip) ->
453470
Result = query(Ip, 64),
454471
Result#ip2proxyrecord.is_proxy.
@@ -519,6 +536,7 @@ query(Ip, Mode) ->
519536
asn = X,
520537
as = X,
521538
last_seen = X,
539+
threat = X,
522540
is_proxy = -1
523541
}
524542
end,
@@ -537,6 +555,7 @@ query(Ip, Mode) ->
537555
asn = Y,
538556
as = Y,
539557
last_seen = Y,
558+
threat = Y,
540559
is_proxy = -1
541560
}
542561
end

test.erl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ printme(V) ->
55
case V of
66
{} ->
77
io:format("No results.~n", []);
8-
{ip2proxyrecord, Country_short, Country_long, Region, City, Isp, Proxy_type, Domain, Usage_type, Asn, As, Last_seen, Is_proxy} ->
8+
{ip2proxyrecord, Country_short, Country_long, Region, City, Isp, Proxy_type, Domain, Usage_type, Asn, As, Last_seen, Threat, 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]),
@@ -17,13 +17,14 @@ printme(V) ->
1717
io:format("Asn: ~p~n", [Asn]),
1818
io:format("As: ~p~n", [As]),
1919
io:format("Last_seen: ~p~n", [Last_seen]),
20+
io:format("Threat: ~p~n", [Threat]),
2021
io:format("Is_proxy: ~p~n", [Is_proxy])
2122
end,
2223
io:format("===================================================================~n", []).
2324

2425
testme() ->
2526
X = "37.252.228.50",
26-
case ip2proxy:open("./IP2Proxy/bin/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN.BIN") of
27+
case ip2proxy:open("./IP2Proxy/bin/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL.BIN") of
2728
0 ->
2829
io:format("getpackageversion: ~p~n", [ip2proxy:getpackageversion()]),
2930
io:format("getmoduleversion: ~p~n", [ip2proxy:getmoduleversion()]),
@@ -42,6 +43,7 @@ testme() ->
4243
io:format("Asn: ~p~n", [ip2proxy:getasn(X)]),
4344
io:format("AS: ~p~n", [ip2proxy:getas(X)]),
4445
io:format("Last_seen: ~p~n", [ip2proxy:getlastseen(X)]),
46+
io:format("Threat: ~p~n", [ip2proxy:getthreat(X)]),
4547
io:format("Is_proxy: ~p~n", [ip2proxy:isproxy(X)]);
4648
_ ->
4749
io:format("Error reading BIN file~n", [])

0 commit comments

Comments
 (0)