diff --git a/LICENSE.TXT b/LICENSE.TXT index b1aebb5..1f446b9 100644 --- a/LICENSE.TXT +++ b/LICENSE.TXT @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 IP2Location.com +Copyright (c) 2020 IP2Location.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 2a2a3a7..2e12cb0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # IP2Proxy Erlang Module -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 +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 * Free IP2Proxy BIN Data: https://lite.ip2location.com * Commercial IP2Proxy BIN Data: https://www.ip2location.com/database/ip2proxy @@ -19,22 +19,23 @@ Below are the methods supported in this package. |---|---| |open|Open the IP2Proxy BIN data for lookup.| |close|Close and clean up metadata.| -|getpackageversion|Get the package version (1 to 8 for PX1 to PX8 respectively).| +|getpackageversion|Get the package version (1 to 10 for PX1 to PX10 respectively).| |getmoduleversion|Get the module version.| |getdatabaseversion|Get the database version.| |isproxy|Check whether if an IP address was a proxy. Returned value:| |getall|Return the proxy information in an array.| -|getproxytype|Return the proxy type. Please visit IP2Location for the list of proxy types supported.| +|getproxytype|Return the proxy type. Please visit IP2Location for the list of proxy types supported.| |getcountryshort|Return the ISO3166-1 country code (2-digits) of the proxy.| |getcountrylong|Return the ISO3166-1 country name of the proxy.| |getregion|Return the ISO3166-2 region name of the proxy. Please visit ISO3166-2 Subdivision Code for the information of ISO3166-2 supported.| |getcity|Return the city name of the proxy.| |getisp|Return the ISP name of the proxy.| |getdomain|Return the domain name of the proxy.| -|getusagetype|Return the usage type classification of the proxy. Please visit IP2Location for the list of usage types supported.| +|getusagetype|Return the usage type classification of the proxy. Please visit IP2Location for the list of usage types supported.| |getasn|Return the autonomous system number of the proxy.| |getas|Return the autonomous system name of the proxy.| |getlastseen|Return the number of days that the proxy was last seen.| +|getthreat|Return the threat type of the proxy.| ## Example diff --git a/ip2proxy.erl b/ip2proxy.erl index a6ca1ab..41fb6b5 100644 --- a/ip2proxy.erl +++ b/ip2proxy.erl @@ -1,5 +1,5 @@ -module(ip2proxy). --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]). +-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]). -record(ip2proxyrecord, { country_short = "-", country_long = "-", @@ -12,6 +12,7 @@ asn = "-", as = "-", last_seen = "-", + threat = "-", is_proxy = 0 }). -define(IF(Cond), (case (Cond) of true -> (0); false -> (1) end)). @@ -32,7 +33,7 @@ getpackageversion() -> end. getmoduleversion() -> - "2.2.0". + "3.0.0". getdatabaseversion() -> case ets:info(mymeta) of @@ -186,16 +187,17 @@ readcolstringrow(S, R, Dbtype, Col) -> end. readrecord(S, Dbtype, Rowoffset, Mode) -> - Country_position = [0, 2, 3, 3, 3, 3, 3, 3, 3], - Region_position = [0, 0, 0, 4, 4, 4, 4, 4, 4], - City_position = [0, 0, 0, 5, 5, 5, 5, 5, 5], - Isp_position = [0, 0, 0, 0, 6, 6, 6, 6, 6], - Proxytype_position = [0, 0, 2, 2, 2, 2, 2, 2, 2], - Domain_position = [0, 0, 0, 0, 0, 7, 7, 7, 7], - Usagetype_position = [0, 0, 0, 0, 0, 0, 8, 8, 8], - Asn_position = [0, 0, 0, 0, 0, 0, 0, 9, 9], - As_position = [0, 0, 0, 0, 0, 0, 0, 10, 10], - Lastseen_position = [0, 0, 0, 0, 0, 0, 0, 0, 11], + Country_position = [0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3], + Region_position = [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4], + City_position = [0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5], + Isp_position = [0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6], + Proxytype_position = [0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2], + Domain_position = [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7], + Usagetype_position = [0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8], + Asn_position = [0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9], + As_position = [0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10], + Lastseen_position = [0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11], + Threat_position = [0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12], Countryshort_field = 1, Countrylong_field = 2, @@ -209,8 +211,9 @@ readrecord(S, Dbtype, Rowoffset, Mode) -> Asn_field = 512, As_field = 1024, Lastseen_field = 2048, + Threat_field = 4096, - 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), + 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), Rowlength = Cols bsl 2, case file:pread(S, Rowoffset - 1, Rowlength) of @@ -299,6 +302,14 @@ readrecord(S, Dbtype, Rowoffset, Mode) -> Last_seen = "" end, + if + Mode band Threat_field /= 0 -> + % Threat = readcolstring(S, Dbtype, Rowoffset, Threat_position); + Threat = readcolstringrow(S, R, Dbtype, Threat_position); + true -> + Threat = "" + end, + if (Country_short == "-") or (Proxy_type == "-") -> Is_proxy = 0; @@ -323,6 +334,7 @@ readrecord(S, Dbtype, Rowoffset, Mode) -> asn = Asn, as = As, last_seen = Last_seen, + threat = Threat, is_proxy = Is_proxy } end. @@ -376,6 +388,7 @@ searchtree(S, Ipnum, Dbtype, Low, High, BaseAddr, Colsize, Iptype, Mode) -> asn = X, as = X, last_seen = X, + threat = X, is_proxy = -1 } end. @@ -403,7 +416,7 @@ search6(S, Ipnum, Dbtype, Low, High, Baseaddr, Indexbaseaddr, Colsize, Mode) -> end. getall(Ip) -> - query(Ip, 4095). + query(Ip, 8191). getcountryshort(Ip) -> Result = query(Ip, 1), @@ -449,6 +462,10 @@ getlastseen(Ip) -> Result = query(Ip, 2048), Result#ip2proxyrecord.last_seen. +getthreat(Ip) -> + Result = query(Ip, 4096), + Result#ip2proxyrecord.threat. + isproxy(Ip) -> Result = query(Ip, 64), Result#ip2proxyrecord.is_proxy. @@ -519,6 +536,7 @@ query(Ip, Mode) -> asn = X, as = X, last_seen = X, + threat = X, is_proxy = -1 } end, @@ -537,6 +555,7 @@ query(Ip, Mode) -> asn = Y, as = Y, last_seen = Y, + threat = Y, is_proxy = -1 } end diff --git a/test.erl b/test.erl index 0bb673b..f31ce71 100644 --- a/test.erl +++ b/test.erl @@ -5,7 +5,7 @@ printme(V) -> case V of {} -> io:format("No results.~n", []); - {ip2proxyrecord, Country_short, Country_long, Region, City, Isp, Proxy_type, Domain, Usage_type, Asn, As, Last_seen, Is_proxy} -> + {ip2proxyrecord, Country_short, Country_long, Region, City, Isp, Proxy_type, Domain, Usage_type, Asn, As, Last_seen, Threat, Is_proxy} -> io:format("Country_short: ~p~n", [Country_short]), io:format("Country_long: ~p~n", [Country_long]), io:format("Region: ~p~n", [Region]), @@ -17,13 +17,14 @@ printme(V) -> io:format("Asn: ~p~n", [Asn]), io:format("As: ~p~n", [As]), io:format("Last_seen: ~p~n", [Last_seen]), + io:format("Threat: ~p~n", [Threat]), io:format("Is_proxy: ~p~n", [Is_proxy]) end, io:format("===================================================================~n", []). testme() -> X = "37.252.228.50", - case ip2proxy:open("./IP2Proxy/bin/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN.BIN") of + case ip2proxy:open("./IP2Proxy/bin/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL.BIN") of 0 -> io:format("getpackageversion: ~p~n", [ip2proxy:getpackageversion()]), io:format("getmoduleversion: ~p~n", [ip2proxy:getmoduleversion()]), @@ -42,6 +43,7 @@ testme() -> io:format("Asn: ~p~n", [ip2proxy:getasn(X)]), io:format("AS: ~p~n", [ip2proxy:getas(X)]), io:format("Last_seen: ~p~n", [ip2proxy:getlastseen(X)]), + io:format("Threat: ~p~n", [ip2proxy:getthreat(X)]), io:format("Is_proxy: ~p~n", [ip2proxy:isproxy(X)]); _ -> io:format("Error reading BIN file~n", [])