To determine the proxy type of an IP address using IP2Location.io in Erlang, you can use the IP2Location.io API to retrieve geolocation and related data. For proxy types supported, please see API documentation for more info.
sudo apt install erlang-jiffy
-module(test).
-export([runtest/0]).
runtest() ->
Key = "YOUR_API_KEY",
IP = "8.8.8.8",
ssl:start(),
inets:start(),
MyParams = uri_string:compose_query([{"format", "json"}, {"key", Key}, {"ip", IP}]),
case httpc:request(get, {"https://api.ip2location.io/?" ++ MyParams, []}, [{ssl, [{versions, ['tlsv1.2']}]}, {autoredirect, false}], []) of
{ok, {{_, 200, _}, _, Body}} ->
Result = jiffy:decode(unicode:characters_to_binary(Body,unicode,utf8),[return_maps]),
case maps:is_key(<<"proxy">>, Result) of
true ->
Proxy = maps:get(<<"proxy">>, Result),
ProxyType = maps:get(<<"proxy_type">>, Proxy),
io:format("The proxy type for IP ~s is ~s.~n", [IP, ProxyType]);
_ ->
io:format("ERROR: The proxy_type field requires a paid subscription to the Security plan.~n", [])
end;
{ok, {{_, 400, _}, _, Body}} ->
Result = jiffy:decode(unicode:characters_to_binary(Body,unicode,utf8),[return_maps]),
case maps:is_key(<<"error">>, Result) of
true ->
Error = maps:get(<<"error">>, Result),
io:format("ERROR: ~s~n", [maps:get(<<"error_message">>, Error)]);
_ ->
io:format("ERROR: ~p~n", [Result])
end;
{ok, {{_, 401, _}, _, Body}} ->
Result = jiffy:decode(unicode:characters_to_binary(Body,unicode,utf8),[return_maps]),
case maps:is_key(<<"error">>, Result) of
true ->
Error = maps:get(<<"error">>, Result),
io:format("ERROR: ~s~n", [maps:get(<<"error_message">>, Error)]);
_ ->
io:format("ERROR: ~p~n", [Result])
end;
{error, Reason} ->
io:format("ERROR ~p~n", [Reason])
end.
erl
c(test).
test:runtest().
This script will output the proxy type of specified IP address. Make sure to replace 8.8.8.8 with the IP address you want and replace YOUR_API_KEY to your own API key.
Empower your applications with accurate IP geolocation information now.
Try It for Free