Skip to content

About

This is a pre-configured, ready-to-run PostgreSQL server with IP2Proxy database setup scripts. It simplifies the development team to install and set up the IP Proxy database in PostgreSQL server.

Resources

Stars

4 stars

Watchers

1 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docker-ip2proxy-postgresql

A ready-to-run PostgreSQL server preloaded with an IP2Proxy proxy IP database. Supports the commercial packages and the free LITE package. Register for an account first as download token is required.

Usage

docker network create ip2proxy-network

docker run --name ip2proxy \
  --network ip2proxy-network \
  -d \
  -e TOKEN={DOWNLOAD_TOKEN} \
  -e CODE={DOWNLOAD_CODE} \
  -e IP_TYPE=IPV4 \
  -e POSTGRESQL_PASSWORD={POSTGRESQL_PASSWORD} \
  ip2proxy/postgresql

docker logs -f ip2proxy      # Wait for "✓ Setup completed"

ENV Variables

Variable Description
TOKEN Download token. Required.
CODE Database code. Required. See below.
IP_TYPE IPV4 (default) or IPV6.
POSTGRESQL_PASSWORD Password for the postgres role. Random if omitted.

CODE — Free Database: PX1-LITE, PX2-LITE, PX3-LITE, PX4-LITE, PX5-LITE, PX6-LITE, PX7-LITE, PX8-LITE, PX9-LITE, PX10-LITE, PX11-LITE, PX12-LITE. Commercial Database: PX1, PX2, PX3, PX4, PX5, PX6, PX7, PX8, PX9, PX10, PX11, PX12.

Only one address family is installed per container. To switch, start a fresh container with an empty /var/lib/postgresql — an existing install is not converted in place, and re-running with different settings prints a note explaining that.

The password is written to /ip2proxy.conf inside the container, so docker logs and docker exec access are equivalent to knowing it.

To start over:

docker rm -f ip2proxy
docker volume rm ip2proxy-data        # if you used -v ip2proxy-data:/var/lib/postgresql

Query for IP Information

The table stores each entry as an ip_from/ip_to number range. A built-in IP_ATON() converts an address to that number, so you can query with the address directly:

SELECT * FROM ip2proxy_database WHERE IP_ATON('8.8.8.8'::inet) BETWEEN ip_from AND ip_to LIMIT 1;

Both bounds are required. The database lists only addresses that have proxy data, so the ranges are sparse: they do not cover the address space and most addresses sit in a gap between two ranges. Matching on ip_to alone (IP_ATON('8.8.8.8'::inet) <= ip_to LIMIT 1) matches millions of rows and returns an arbitrary one of them, so it reports a proxy record for an address that is not a proxy. BETWEEN ip_from AND ip_to matches the single range that actually contains the address, or nothing.

IP_ATON() handles both IPv4 and IPv6, so the same query works whichever IP_TYPE you installed. It is created during setup and is executable by public.

No row returned means the address is not in the database. For IP2Proxy that is the ordinary result for most addresses, since only a small share of the address space carries proxy data.

Connect from an Application

Put your application on the same network and reach the container by name (ip2proxy):

docker run --network ip2proxy-network -t -i {YOUR_APPLICATION}
psql -h ip2proxy -U postgres -d ip2proxy_database

Update IP2Proxy Database

docker exec -it ip2proxy /update.sh

Downloads a fresh copy and swaps it in, so queries keep working against the old data until the swap. The daily download quota is limited. If you get [QUOTA EXCEEDED] error, please try again after 24 hours.

Articles and Tutorials

IP2Proxy Articles and Tutorials

About

This is a pre-configured, ready-to-run PostgreSQL server with IP2Proxy database setup scripts. It simplifies the development team to install and set up the IP Proxy database in PostgreSQL server.

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages