To determine the proxy type of an IP address using IP2Location.io in OCaml, you can use the IP2Location.io API to retrieve geolocation and related data. For proxy types supported, please see API documentation for more info.
dune init proj example
cd example
opam install lwt cohttp cohttp-lwt-unix yojson
(executable
(public_name example)
(name main)
(libraries example lwt cohttp cohttp-lwt-unix yojson))
open Printf
open Lwt
open Cohttp
open Cohttp_lwt_unix
open Yojson
let () =
let ip = "8.8.8.8" in
let key = "YOUR_API_KEY" in
let uri =
Uri.of_string
("https://api.ip2location.io/?format=json&key=" ^ key ^ "&ip=" ^ ip)
in
Lwt_main.run
( Client.get uri >>= fun (resp, body) ->
let code = resp |> Response.status |> Code.code_of_status in
let json_promise = body |> Cohttp_lwt.Body.to_string in
json_promise >|= fun json_string ->
let json = Basic.from_string json_string in
let open Yojson.Basic.Util in
match code with
| 200 when member "proxy" json <> `Null ->
json |> member "proxy" |> member "proxy_type" |> to_string
|> printf "The proxy type for IP %s is %s.\n" ip
| 200 ->
printf
"ERROR: The proxy_type field requires a paid subscription to the \
Security plan.\n"
| (400 | 401) when member "error" json <> `Null ->
json |> member "error" |> member "error_message" |> to_string
|> printf "ERROR: %s\n"
| _ -> printf "HTTP Code: %d\n" code )
dune build
dune exec example
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