How to use IP2Proxy in Deno?

IP2Proxy proxy detection in Deno

Deno is a runtime designed for JavaScript, TypeScript, and WebAssembly languages. It’s built based on the V8 JavaScript engine and Rust programming language. Deno had been distributed as a single executable without any dependencies needed. User can just install and run without any worries. In addition, Deno supports the import of third party modules to be used in the script. For example, user can import a module to query the proxy information of a particular IP address.

In this article, we are going to guide you on how to use IP2Proxy in Deno. You will learn how to use the IP2Proxy Deno module and the IP2Proxy BIN database to query the proxy information of an IP address.

Installation

Before we start, you will need to download the latest release from https://github.com/ip2location/ip2proxy-deno/releases, unzip it and copy the mode.ts file and /src folder into your project root folder.

You will also need the IP2Proxy BIN database. You can download a free database from https://lite.ip2location.com or purchase a commercial database from https://www.ip2location.com/database/ip2proxy.

IP2Location LITE database

Steps

  1. Create a new js file called query_ip.js in your project root folder, copy the following piece of code into the file, and change the “YOUR_DATABASE_PATH” to the database you have obtained earlier:
import { IP2Proxy } from "./mod.ts";

let ip2proxy = new IP2Proxy();

if (ip2proxy.open(YOUR_DATABASE_PATH) == 0) {

    let ip = '199.83.103.79';
    let all = ip2proxy.getAll(ip);
    console.log("isProxy: " + all.isProxy);
    console.log("proxyType: " + all.proxyType);
    console.log("countryShort: " + all.countryShort);
    console.log("countryLong: " + all.countryLong);
    console.log("region: " + all.region);
    console.log("city: " + all.city);
    console.log("isp: " + all.isp);
    console.log("domain: " + all.domain);
    console.log("usagetype: " + all.usageType);
    console.log("asn: " + all.asn);
    console.log("as: " + all.as);
    console.log("lastSeen: " + all.lastSeen);
    console.log("threat: " + all.threat);
    console.log("provider: " + all.provider);
}
else {
    console.log("Error reading BIN file.");
}
  1. In your terminal, enter the following command to run the script: deno run --allow-env --allow-read query_ip.js. You will see the result showing up like the screenshot below:
Proxy detection lookup

Conclusion

Throughout this article, you will have learned how to use the IP2Proxy Deno module to query the proxy information of an IP address. You can then make use of the proxy data. For example, you can identify whether your visitor uses a VPN to browse your website, or does the IP address pose a threat. This will help in various situation, such as securing your website from attack by anonymous parties, or to validate the order received from your customer.

Was this article helpful?

Related Articles