The aim of this guide is to demonstrate how to import IP2Proxy data in CSV form into Redis and then query the data in a PHP web page.
First of all, you will need to download the IP2Proxy CSV file. You can use any of the PX packages from PX1 to PX10.
Download Free LITE version at https://lite.ip2location.com/
Download commercial version at https://www.ip2location.com/download
Extract out the file from the downloaded zipped file.
Important Note
We will not cover installation of Redis, Perl or PHP in this guide. We will assume you have already setup Redis on the localhost and are using PHP via Apache (also on the localhost). For this example, we are using a Debian Linux.
More info can be found at the following URLs if you need assistance with installations:
PHP: http://php.net/manual/en/install.unix.debian.php
Redis: http://redis.io/download
Perl Redis Library: http://search.cpan.org/~dams/Redis/lib/Redis.pm
PHP Redis Library: http://pecl.php.net/package/redis
We will be using the Perl Redis library to do mass import of CSV data into Redis and then querying the data via PHP using the PHP Redis library.
Importing the CSV data into Redis
As mentioned earlier, we will be using a Perl script to perform the import of the CSV data into Redis as we need to format our CSV data into an easier to store form.
Create a new Perl file called importredis.pl and paste the following code into it:
use strict; use Redis; my $filename = 'IP2PROXY-IP-COUNTRY.CSV'; # PX1 my $data = ''; my $dbname = 'PX1'; my $client = Redis->new( server => 'localhost:6379', password => 'your_redis_password' ); $client->del($dbname); open IN, "<$filename" or die; my $counter = 0; my $line = ''; while () { $line = $_; $line =~ s/[\r\n]+//; # remove EOL if ($line =~ /^"([^"]+)","([^"]+)","([^"]+)","([^"]+)"$/) { $counter++; my $ipfrom = $1; my $ipto = $2; my $countrycode = $3; my $countryname = $4; my $datastr = '"' . $ipfrom . "|" . $ipto . "|" . $countrycode . "|" . $countryname . '"'; $datastr =~ s/([\@\%\$])/\\\1/g; $data .= ', ' . $ipfrom . ' => ' . $datastr; if ($counter % 5000 == 0) { print "Running line $counter\n"; &runMe($data); $data = ''; } } } if ($data ne '') { &runMe($data); $data = ''; } close IN; sub runMe { my $mydata = shift; eval('$client->zadd($dbname' . $mydata . ');'); warn $@ if $@; }
use strict; use Redis; my $filename = 'IP2PROXY-IP-PROXYTYPE-COUNTRY.CSV'; # PX2 my $data = ''; my $dbname = 'PX2'; my $client = Redis->new( server => 'localhost:6379', password => 'your_redis_password' ); $client->del($dbname); open IN, "<$filename" or die; my $counter = 0; my $line = ''; while () { $line = $_; $line =~ s/[\r\n]+//; # remove EOL if ($line =~ /^"([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)"$/) { $counter++; my $ipfrom = $1; my $ipto = $2; my $proxytype = $3; my $countrycode = $4; my $countryname = $5; my $datastr = '"' . $ipfrom . "|" . $ipto . "|" . $proxytype . "|" . $countrycode . "|" . $countryname . '"'; $datastr =~ s/([\@\%\$])/\\\1/g; $data .= ', ' . $ipfrom . ' => ' . $datastr; if ($counter % 5000 == 0) { print "Running line $counter\n"; &runMe($data); $data = ''; } } } if ($data ne '') { &runMe($data); $data = ''; } close IN; sub runMe { my $mydata = shift; eval('$client->zadd($dbname' . $mydata . ');'); warn $@ if $@; }
use strict; use Redis; my $filename = 'IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY.CSV'; # PX3 my $data = ''; my $dbname = 'PX3'; my $client = Redis->new( server => 'localhost:6379', password => 'your_redis_password' ); $client->del($dbname); open IN, "<$filename" or die; my $counter = 0; my $line = ''; while () { $line = $_; $line =~ s/[\r\n]+//; # remove EOL if ($line =~ /^"([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)"$/) { $counter++; my $ipfrom = $1; my $ipto = $2; my $proxytype = $3; my $countrycode = $4; my $countryname = $5; my $regionname = $6; my $cityname = $7; my $datastr = '"' . $ipfrom . "|" . $ipto . "|" . $proxytype . "|" . $countrycode . "|" . $countryname . "|" . $regionname . "|" . $cityname . '"'; $datastr =~ s/([\@\%\$])/\\\1/g; $data .= ', ' . $ipfrom . ' => ' . $datastr; if ($counter % 5000 == 0) { print "Running line $counter\n"; &runMe($data); $data = ''; } } } if ($data ne '') { &runMe($data); $data = ''; } close IN; sub runMe { my $mydata = shift; eval('$client->zadd($dbname' . $mydata . ');'); warn $@ if $@; }
use strict; use Redis; my $filename = 'IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.CSV'; # PX4 my $data = ''; my $dbname = 'PX4'; my $client = Redis->new( server => 'localhost:6379', password => 'your_redis_password' ); $client->del($dbname); open IN, "<$filename" or die; my $counter = 0; my $line = ''; while () { $line = $_; $line =~ s/[\r\n]+//; # remove EOL if ($line =~ /^"([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)"$/) { $counter++; my $ipfrom = $1; my $ipto = $2; my $proxytype = $3; my $countrycode = $4; my $countryname = $5; my $regionname = $6; my $cityname = $7; my $isp = $8; my $datastr = '"' . $ipfrom . "|" . $ipto . "|" . $proxytype . "|" . $countrycode . "|" . $countryname . "|" . $regionname . "|" . $cityname . "|" . $isp . '"'; $datastr =~ s/([\@\%\$])/\\\1/g; $data .= ', ' . $ipfrom . ' => ' . $datastr; if ($counter % 5000 == 0) { print "Running line $counter\n"; &runMe($data); $data = ''; } } } if ($data ne '') { &runMe($data); $data = ''; } close IN; sub runMe { my $mydata = shift; eval('$client->zadd($dbname' . $mydata . ');'); warn $@ if $@; }
use strict; use Redis; my $filename = 'IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN.CSV'; # PX5 my $data = ''; my $dbname = 'PX5'; my $client = Redis->new( server => 'localhost:6379', password => 'your_redis_password' ); $client->del($dbname); open IN, "<$filename" or die; my $counter = 0; my $line = ''; while () { $line = $_; $line =~ s/[\r\n]+//; # remove EOL if ($line =~ /^"([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)"$/) { $counter++; my $ipfrom = $1; my $ipto = $2; my $proxytype = $3; my $countrycode = $4; my $countryname = $5; my $regionname = $6; my $cityname = $7; my $isp = $8; my $domain = $9; my $datastr = '"' . $ipfrom . "|" . $ipto . "|" . $proxytype . "|" . $countrycode . "|" . $countryname . "|" . $regionname . "|" . $cityname . "|" . $isp . "|" . $domain . '"'; $datastr =~ s/([\@\%\$])/\\\1/g; $data .= ', ' . $ipfrom . ' => ' . $datastr; if ($counter % 5000 == 0) { print "Running line $counter\n"; &runMe($data); $data = ''; } } } if ($data ne '') { &runMe($data); $data = ''; } close IN; sub runMe { my $mydata = shift; eval('$client->zadd($dbname' . $mydata . ');'); warn $@ if $@; }
use strict; use Redis; my $filename = 'IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE.CSV'; # PX6 my $data = ''; my $dbname = 'PX6'; my $client = Redis->new( server => 'localhost:6379', password => 'your_redis_password' ); $client->del($dbname); open IN, "<$filename" or die; my $counter = 0; my $line = ''; while () { $line = $_; $line =~ s/[\r\n]+//; # remove EOL if ($line =~ /^"([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)"$/) { $counter++; my $ipfrom = $1; my $ipto = $2; my $proxytype = $3; my $countrycode = $4; my $countryname = $5; my $regionname = $6; my $cityname = $7; my $isp = $8; my $domain = $9; my $usagetype = $10; my $datastr = '"' . $ipfrom . "|" . $ipto . "|" . $proxytype . "|" . $countrycode . "|" . $countryname . "|" . $regionname . "|" . $cityname . "|" . $isp . "|" . $domain . "|" . $usagetype . '"'; $datastr =~ s/([\@\%\$])/\\\1/g; $data .= ', ' . $ipfrom . ' => ' . $datastr; if ($counter % 5000 == 0) { print "Running line $counter\n"; &runMe($data); $data = ''; } } } if ($data ne '') { &runMe($data); $data = ''; } close IN; sub runMe { my $mydata = shift; eval('$client->zadd($dbname' . $mydata . ');'); warn $@ if $@; }
use strict; use Redis; my $filename = 'IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN.CSV'; # PX7 my $data = ''; my $dbname = 'PX7'; my $client = Redis->new( server => 'localhost:6379', password => 'your_redis_password' ); $client->del($dbname); open IN, "<$filename" or die; my $counter = 0; my $line = ''; while () { $line = $_; $line =~ s/[\r\n]+//; # remove EOL if ($line =~ /^"([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)"$/) { $counter++; my $ipfrom = $1; my $ipto = $2; my $proxytype = $3; my $countrycode = $4; my $countryname = $5; my $regionname = $6; my $cityname = $7; my $isp = $8; my $domain = $9; my $usagetype = $10; my $asn = $11; my $as = $12; my $datastr = '"' . $ipfrom . "|" . $ipto . "|" . $proxytype . "|" . $countrycode . "|" . $countryname . "|" . $regionname . "|" . $cityname . "|" . $isp . "|" . $domain . "|" . $usagetype . "|" . $asn . "|" . $as . '"'; $datastr =~ s/([\@\%\$])/\\\1/g; $data .= ', ' . $ipfrom . ' => ' . $datastr; if ($counter % 5000 == 0) { print "Running line $counter\n"; &runMe($data); $data = ''; } } } if ($data ne '') { &runMe($data); $data = ''; } close IN; sub runMe { my $mydata = shift; eval('$client->zadd($dbname' . $mydata . ');'); warn $@ if $@; }
use strict; use Redis; my $filename = 'IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN.CSV'; # PX8 my $data = ''; my $dbname = 'PX8'; my $client = Redis->new( server => 'localhost:6379', password => 'your_redis_password' ); $client->del($dbname); open IN, "<$filename" or die; my $counter = 0; my $line = ''; while () { $line = $_; $line =~ s/[\r\n]+//; # remove EOL if ($line =~ /^"([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)"$/) { $counter++; my $ipfrom = $1; my $ipto = $2; my $proxytype = $3; my $countrycode = $4; my $countryname = $5; my $regionname = $6; my $cityname = $7; my $isp = $8; my $domain = $9; my $usagetype = $10; my $asn = $11; my $as = $12; my $lastseen = $13; my $datastr = '"' . $ipfrom . "|" . $ipto . "|" . $proxytype . "|" . $countrycode . "|" . $countryname . "|" . $regionname . "|" . $cityname . "|" . $isp . "|" . $domain . "|" . $usagetype . "|" . $asn . "|" . $as . "|" . $lastseen . '"'; $datastr =~ s/([\@\%\$])/\\\1/g; $data .= ', ' . $ipfrom . ' => ' . $datastr; if ($counter % 5000 == 0) { print "Running line $counter\n"; &runMe($data); $data = ''; } } } if ($data ne '') { &runMe($data); $data = ''; } close IN; sub runMe { my $mydata = shift; eval('$client->zadd($dbname' . $mydata . ');'); warn $@ if $@; }
use strict; use Redis; my $filename = 'IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT.CSV'; # PX9 my $data = ''; my $dbname = 'PX9'; my $client = Redis->new( server => 'localhost:6379', password => 'your_redis_password' ); $client->del($dbname); open IN, "<$filename" or die; my $counter = 0; my $line = ''; while () { $line = $_; $line =~ s/[\r\n]+//; # remove EOL if ($line =~ /^"([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)"$/) { $counter++; my $ipfrom = $1; my $ipto = $2; my $proxytype = $3; my $countrycode = $4; my $countryname = $5; my $regionname = $6; my $cityname = $7; my $isp = $8; my $domain = $9; my $usagetype = $10; my $asn = $11; my $as = $12; my $lastseen = $13; my $threat = $14; my $datastr = '"' . $ipfrom . "|" . $ipto . "|" . $proxytype . "|" . $countrycode . "|" . $countryname . "|" . $regionname . "|" . $cityname . "|" . $isp . "|" . $domain . "|" . $usagetype . "|" . $asn . "|" . $as . "|" . $lastseen . "|" . $threat . '"'; $datastr =~ s/([\@\%\$])/\\\1/g; $data .= ', ' . $ipfrom . ' => ' . $datastr; if ($counter % 5000 == 0) { print "Running line $counter\n"; &runMe($data); $data = ''; } } } if ($data ne '') { &runMe($data); $data = ''; } close IN; sub runMe { my $mydata = shift; eval('$client->zadd($dbname' . $mydata . ');'); warn $@ if $@; }
use strict; use Redis; my $filename = 'IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL.CSV'; # PX10 my $data = ''; my $dbname = 'PX10'; my $client = Redis->new( server => 'localhost:6379', password => 'your_redis_password' ); $client->del($dbname); open IN, "<$filename" or die; my $counter = 0; my $line = ''; while () { $line = $_; $line =~ s/[\r\n]+//; # remove EOL if ($line =~ /^"([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)","([^"]+)"$/) { $counter++; my $ipfrom = $1; my $ipto = $2; my $proxytype = $3; my $countrycode = $4; my $countryname = $5; my $regionname = $6; my $cityname = $7; my $isp = $8; my $domain = $9; my $usagetype = $10; my $asn = $11; my $as = $12; my $lastseen = $13; my $threat = $14; my $datastr = '"' . $ipfrom . "|" . $ipto . "|" . $proxytype . "|" . $countrycode . "|" . $countryname . "|" . $regionname . "|" . $cityname . "|" . $isp . "|" . $domain . "|" . $usagetype . "|" . $asn . "|" . $as . "|" . $lastseen . "|" . $threat . '"'; $datastr =~ s/([\@\%\$])/\\\1/g; $data .= ', ' . $ipfrom . ' => ' . $datastr; if ($counter % 5000 == 0) { print "Running line $counter\n"; &runMe($data); $data = ''; } } } if ($data ne '') { &runMe($data); $data = ''; } close IN; sub runMe { my $mydata = shift; eval('$client->zadd($dbname' . $mydata . ');'); warn $@ if $@; }
Run the Perl script by calling the below command in command prompt:
perl importredis.pl
Querying the IP2Proxy data from a PHP web page
Now, create a PHP file called test.php in your website.
Paste the following PHP code into it and then run it in the browser:
connect('127.0.0.1'); // port 6379 by default if ($redis->auth('your_redis_password')) { $ipnum = sprintf("%u", ip2long($myip)); $result = $redis->zRevRangeByScore('PX1', $ipnum, 0, array('limit' => array(0, 1))); if (!empty($result)) { $result = $result[0]; $arr = explode("|", $result); if ($arr[1] >= $ipnum) { echo "is proxy
\n"; echo "country code: " . $arr[2] . "
\n"; echo "country name: " . $arr[3] . "
\n"; } else { echo "Not proxy
\n"; } } else { echo "Not proxy
\n"; } } else { echo "Incorrect password\n"; } $redis->close(); } queryIP2Proxy($ip); ?>
connect('127.0.0.1'); // port 6379 by default if ($redis->auth('your_redis_password')) { $ipnum = sprintf("%u", ip2long($myip)); $result = $redis->zRevRangeByScore('PX2', $ipnum, 0, array('limit' => array(0, 1))); if (!empty($result)) { $result = $result[0]; $arr = explode("|", $result); if ($arr[1] >= $ipnum) { echo "is proxy
\n"; echo "proxy type: " . $arr[2] . "
\n"; echo "country code: " . $arr[3] . "
\n"; echo "country name: " . $arr[4] . "
\n"; } else { echo "Not proxy
\n"; } } else { echo "Not proxy
\n"; } } else { echo "Incorrect password\n"; } $redis->close(); } queryIP2Proxy($ip); ?>
connect('127.0.0.1'); // port 6379 by default if ($redis->auth('your_redis_password')) { $ipnum = sprintf("%u", ip2long($myip)); $result = $redis->zRevRangeByScore('PX3', $ipnum, 0, array('limit' => array(0, 1))); if (!empty($result)) { $result = $result[0]; $arr = explode("|", $result); if ($arr[1] >= $ipnum) { echo "is proxy
\n"; echo "proxy type: " . $arr[2] . "
\n"; echo "country code: " . $arr[3] . "
\n"; echo "country name: " . $arr[4] . "
\n"; echo "region name: " . $arr[5] . "
\n"; echo "city name: " . $arr[6] . "
\n"; } else { echo "Not proxy
\n"; } } else { echo "Not proxy
\n"; } } else { echo "Incorrect password\n"; } $redis->close(); } queryIP2Proxy($ip); ?>
connect('127.0.0.1'); // port 6379 by default if ($redis->auth('your_redis_password')) { $ipnum = sprintf("%u", ip2long($myip)); $result = $redis->zRevRangeByScore('PX4', $ipnum, 0, array('limit' => array(0, 1))); if (!empty($result)) { $result = $result[0]; $arr = explode("|", $result); if ($arr[1] >= $ipnum) { echo "is proxy
\n"; echo "proxy type: " . $arr[2] . "
\n"; echo "country code: " . $arr[3] . "
\n"; echo "country name: " . $arr[4] . "
\n"; echo "region name: " . $arr[5] . "
\n"; echo "city name: " . $arr[6] . "
\n"; echo "isp: " . $arr[7] . "
\n"; } else { echo "Not proxy
\n"; } } else { echo "Not proxy
\n"; } } else { echo "Incorrect password\n"; } $redis->close(); } queryIP2Proxy($ip); ?>
connect('127.0.0.1'); // port 6379 by default if ($redis->auth('your_redis_password')) { $ipnum = sprintf("%u", ip2long($myip)); $result = $redis->zRevRangeByScore('PX5', $ipnum, 0, array('limit' => array(0, 1))); if (!empty($result)) { $result = $result[0]; $arr = explode("|", $result); if ($arr[1] >= $ipnum) { echo "is proxy
\n"; echo "proxy type: " . $arr[2] . "
\n"; echo "country code: " . $arr[3] . "
\n"; echo "country name: " . $arr[4] . "
\n"; echo "region name: " . $arr[5] . "
\n"; echo "city name: " . $arr[6] . "
\n"; echo "isp: " . $arr[7] . "
\n"; echo "domain: " . $arr[8] . "
\n"; } else { echo "Not proxy
\n"; } } else { echo "Not proxy
\n"; } } else { echo "Incorrect password\n"; } $redis->close(); } queryIP2Proxy($ip); ?>
connect('127.0.0.1'); // port 6379 by default if ($redis->auth('your_redis_password')) { $ipnum = sprintf("%u", ip2long($myip)); $result = $redis->zRevRangeByScore('PX6', $ipnum, 0, array('limit' => array(0, 1))); if (!empty($result)) { $result = $result[0]; $arr = explode("|", $result); if ($arr[1] >= $ipnum) { echo "is proxy
\n"; echo "proxy type: " . $arr[2] . "
\n"; echo "country code: " . $arr[3] . "
\n"; echo "country name: " . $arr[4] . "
\n"; echo "region name: " . $arr[5] . "
\n"; echo "city name: " . $arr[6] . "
\n"; echo "isp: " . $arr[7] . "
\n"; echo "domain: " . $arr[8] . "
\n"; echo "usage type: " . $arr[9] . "
\n"; } else { echo "Not proxy
\n"; } } else { echo "Not proxy
\n"; } } else { echo "Incorrect password\n"; } $redis->close(); } queryIP2Proxy($ip); ?>
connect('127.0.0.1'); // port 6379 by default if ($redis->auth('your_redis_password')) { $ipnum = sprintf("%u", ip2long($myip)); $result = $redis->zRevRangeByScore('PX7', $ipnum, 0, array('limit' => array(0, 1))); if (!empty($result)) { $result = $result[0]; $arr = explode("|", $result); if ($arr[1] >= $ipnum) { echo "is proxy
\n"; echo "proxy type: " . $arr[2] . "
\n"; echo "country code: " . $arr[3] . "
\n"; echo "country name: " . $arr[4] . "
\n"; echo "region name: " . $arr[5] . "
\n"; echo "city name: " . $arr[6] . "
\n"; echo "isp: " . $arr[7] . "
\n"; echo "domain: " . $arr[8] . "
\n"; echo "usage type: " . $arr[9] . "
\n"; echo "asn: " . $arr[10] . "
\n"; echo "as: " . $arr[11] . "
\n"; } else { echo "Not proxy
\n"; } } else { echo "Not proxy
\n"; } } else { echo "Incorrect password\n"; } $redis->close(); } queryIP2Proxy($ip); ?>
connect('127.0.0.1'); // port 6379 by default if ($redis->auth('your_redis_password')) { $ipnum = sprintf("%u", ip2long($myip)); $result = $redis->zRevRangeByScore('PX8', $ipnum, 0, array('limit' => array(0, 1))); if (!empty($result)) { $result = $result[0]; $arr = explode("|", $result); if ($arr[1] >= $ipnum) { echo "is proxy
\n"; echo "proxy type: " . $arr[2] . "
\n"; echo "country code: " . $arr[3] . "
\n"; echo "country name: " . $arr[4] . "
\n"; echo "region name: " . $arr[5] . "
\n"; echo "city name: " . $arr[6] . "
\n"; echo "isp: " . $arr[7] . "
\n"; echo "domain: " . $arr[8] . "
\n"; echo "usage type: " . $arr[9] . "
\n"; echo "asn: " . $arr[10] . "
\n"; echo "as: " . $arr[11] . "
\n"; echo "last seen: " . $arr[12] . "
\n"; } else { echo "Not proxy
\n"; } } else { echo "Not proxy
\n"; } } else { echo "Incorrect password\n"; } $redis->close(); } queryIP2Proxy($ip); ?>
connect('127.0.0.1'); // port 6379 by default if ($redis->auth('your_redis_password')) { $ipnum = sprintf("%u", ip2long($myip)); $result = $redis->zRevRangeByScore('PX9', $ipnum, 0, array('limit' => array(0, 1))); if (!empty($result)) { $result = $result[0]; $arr = explode("|", $result); if ($arr[1] >= $ipnum) { echo "is proxy \n"; echo "proxy type: " . $arr[2] . " \n"; echo "country code: " . $arr[3] . " \n"; echo "country name: " . $arr[4] . " \n"; echo "region name: " . $arr[5] . " \n"; echo "city name: " . $arr[6] . " \n"; echo "isp: " . $arr[7] . " \n"; echo "domain: " . $arr[8] . " \n"; echo "usage type: " . $arr[9] . " \n"; echo "asn: " . $arr[10] . " \n"; echo "as: " . $arr[11] . " \n"; echo "last seen: " . $arr[12] . " \n"; echo "threat: " . $arr[13] . " \n"; } else { echo "Not proxy \n"; } } else { echo "Not proxy \n"; } } else { echo "Incorrect password\n"; } $redis->close(); } queryIP2Proxy($ip); ?>
connect('127.0.0.1'); // port 6379 by default if ($redis->auth('your_redis_password')) { $ipnum = sprintf("%u", ip2long($myip)); $result = $redis->zRevRangeByScore('PX10', $ipnum, 0, array('limit' => array(0, 1))); if (!empty($result)) { $result = $result[0]; $arr = explode("|", $result); if ($arr[1] >= $ipnum) { echo "is proxy \n"; echo "proxy type: " . $arr[2] . " \n"; echo "country code: " . $arr[3] . " \n"; echo "country name: " . $arr[4] . " \n"; echo "region name: " . $arr[5] . " \n"; echo "city name: " . $arr[6] . " \n"; echo "isp: " . $arr[7] . " \n"; echo "domain: " . $arr[8] . " \n"; echo "usage type: " . $arr[9] . " \n"; echo "asn: " . $arr[10] . " \n"; echo "as: " . $arr[11] . " \n"; echo "last seen: " . $arr[12] . " \n"; echo "threat: " . $arr[13] . " \n"; } else { echo "Not proxy \n"; } } else { echo "Not proxy \n"; } } else { echo "Incorrect password\n"; } $redis->close(); } queryIP2Proxy($ip); ?>