Skip to content

Commit 894b32d

Browse files
committed
Added new field "fraudScore" to support PX12 database.
1 parent d0cb91c commit 894b32d

File tree

10 files changed

+140
-102
lines changed

10 files changed

+140
-102
lines changed

LICENSE.TXT

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016 - 2024 IP2Location.com
3+
Copyright (c) 2016 - 2025 IP2Location.com
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ To learn more about installation, usage, and code examples, please visit the dev
2222
| PUB | Public Proxies. These are services which make connection requests on a user's behalf. Proxy server software can be configured by the administrator to listen on some specified port. These differ from VPNs in that the proxies usually have limited functions compare to VPNs. | High |
2323
| WEB | Web Proxies. These are web services which make web requests on a user's behalf. These differ from VPNs or Public Proxies in that they are simple web-based proxies rather than operating at the IP address and other ports level. | High |
2424
| SES | Search Engine Robots. These are services which perform crawling or scraping to a website, such as, the search engine spider or bots engine. | Low |
25-
| RES | Residential proxies. These services offer users proxy connections through residential ISP with or without consents of peers to share their idle resources. Only available with PX10 & PX11 | Medium |
26-
| CPN | Consumer Privacy Network: These services ensure encrypted traffic from the user's browser by routing internet requests through relays, concealing the IP address, location, and browsing activity. Only available with PX11 | Low |
27-
| EPN | Enterprise Private Network: Services like SASE or SD-WAN combine network security functions with wide-area networking (WAN) capabilities to meet the secure remote access needs of organizations. Only available with PX11 | Low |
25+
| RES | Residential proxies. These services offer users proxy connections through residential ISP with or without consents of peers to share their idle resources. Only available with PX10 - PX12 | Medium |
26+
| CPN | Consumer Privacy Network: These services ensure encrypted traffic from the user's browser by routing internet requests through relays, concealing the IP address, location, and browsing activity. Only available with PX11 & PX12 | Low |
27+
| EPN | Enterprise Private Network: Services like SASE or SD-WAN combine network security functions with wide-area networking (WAN) capabilities to meet the secure remote access needs of organizations. Only available with PX11 & PX12 | Low |
2828

2929

3030

data/PX11.SAMPLE.BIN

-1 MB
Binary file not shown.

data/PX12.SAMPLE.BIN

2.43 MB
Binary file not shown.

docs/source/code.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Load the IP2Location BIN database.
99
```
1010

1111
```{py:function} getPackageVersion()
12-
Return the database's type, 1 to 10 respectively for PX1 to PX11. Please visit https://www.ip2location.com/databases/ip2proxy for details.
12+
Return the database's type, 1 to 10 respectively for PX1 to PX12. Please visit https://www.ip2location.com/databases/ip2proxy for details.
1313
1414
:return: Returns the package version.
1515
:rtype: string
@@ -53,4 +53,5 @@ Retrieve geolocation information for an IP address.
5353
| threat | Security threat reported. |
5454
| proxyType | Type of proxy. |
5555
| provider | Name of VPN provider if available. |
56+
| fraudScore | Potential risk score (0 - 99) associated with IP address. |
5657
```

docs/source/quickstart.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ You can query the geolocation information from the IP2Proxy BIN database as belo
2929
```php
3030
require 'vendor/autoload.php';
3131

32-
$db = new \IP2Proxy\Database('vendor/ip2location/ip2proxy-php/data/PX11.SAMPLE.BIN', \IP2PROXY\Database::FILE_IO);
32+
$db = new \IP2Proxy\Database('vendor/ip2location/ip2proxy-php/data/PX12.SAMPLE.BIN', \IP2PROXY\Database::FILE_IO);
3333

3434
$records = $db->lookup('1.0.0.8', \IP2PROXY\Database::ALL);
3535

@@ -42,7 +42,7 @@ echo '<p><strong>State: </strong>' . $records['regionName'] . '</p>';
4242
echo '<p><strong>City: </strong>' . $records['cityName'] . '</p>';
4343

4444
/*
45-
Type of proxy: VPN, TOR, DCH, PUB, WEB, RES (RES available in PX11 only)
45+
Type of proxy: VPN, TOR, DCH, PUB, WEB, RES (RES available in PX11 & PX12 only)
4646
*/
4747
echo '<p><strong>Proxy Type: </strong>' . $records['proxyType'] . '</p>';
4848

@@ -61,4 +61,5 @@ echo '<p><strong>AS: </strong>' . $records['as'] . '</p>';
6161
echo '<p><strong>Last Seen: </strong>' . $records['lastSeen'] . '</p>';
6262
echo '<p><strong>Threat: </strong>' . $records['threat'] . '</p>';
6363
echo '<p><strong>Provider: </strong>' . $records['provider'] . '</p>';
64+
echo '<p><strong>Fraud Score: </strong>' . $records['fraudScore'] . '</p>';
6465
```

examples/example.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
require 'vendor/autoload.php';
77

88
// Lookup by local BIN database
9-
$db = new \IP2Proxy\Database('./data/PX11.SAMPLE.BIN', \IP2PROXY\Database::FILE_IO);
9+
$db = new \IP2Proxy\Database('./data/PX12.SAMPLE.BIN', \IP2PROXY\Database::FILE_IO);
1010

1111
echo 'Module Version: ' . $db->getModuleVersion() . \PHP_EOL . \PHP_EOL;
1212
echo 'Package: PX' . $db->getPackageVersion() . \PHP_EOL;
1313
echo 'Database Date: ' . $db->getDatabaseVersion() . \PHP_EOL;
14-
echo '$records = $db->lookup(\'1.0.0.8\', \IP2PROXY\Database::ALL);' . \PHP_EOL;
15-
$records = $db->lookup('1.0.0.8', \IP2PROXY\Database::ALL);
14+
echo '$records = $db->lookup(\'23.90.12.224\', \IP2PROXY\Database::ALL);' . \PHP_EOL;
15+
$records = $db->lookup('23.83.130.186', \IP2PROXY\Database::ALL);
1616
print_r($records);
1717

1818
echo \PHP_EOL . \PHP_EOL;

src/Database.php

+86-43
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ class Database
148148
*/
149149
public const PROVIDER = 14;
150150

151+
/**
152+
* Fraud score.
153+
*
154+
* @var int
155+
*/
156+
public const FRAUD_SCORE = 15;
157+
151158
/**
152159
* Country name and code.
153160
*
@@ -198,7 +205,7 @@ class Database
198205
*
199206
* @var string
200207
*/
201-
private const VERSION = '4.1.1';
208+
private const VERSION = '4.2.0';
202209

203210
/**
204211
* Include the IP address of the looked up IP address.
@@ -333,20 +340,21 @@ class Database
333340
* @var array
334341
*/
335342
private $columns = [
336-
self::COUNTRY_CODE => [8, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12],
337-
self::COUNTRY_NAME => [8, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12],
338-
self::REGION_NAME => [0, 0, 16, 16, 16, 16, 16, 16, 16, 16, 16],
339-
self::CITY_NAME => [0, 0, 20, 20, 20, 20, 20, 20, 20, 20, 20],
340-
self::ISP => [0, 0, 0, 24, 24, 24, 24, 24, 24, 24, 24],
341-
self::PROXY_TYPE => [0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8],
342-
self::DOMAIN => [0, 0, 0, 0, 28, 28, 28, 28, 28, 28, 28],
343-
self::USAGE_TYPE => [0, 0, 0, 0, 0, 32, 32, 32, 32, 32, 32],
344-
self::ASN => [0, 0, 0, 0, 0, 0, 36, 36, 36, 36, 36],
345-
self::_AS => [0, 0, 0, 0, 0, 0, 40, 40, 40, 40, 40],
346-
self::LAST_SEEN => [0, 0, 0, 0, 0, 0, 0, 44, 44, 44, 44],
347-
self::THREAT => [0, 0, 0, 0, 0, 0, 0, 0, 48, 48, 48],
348-
self::PROVIDER => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 52],
349-
];
343+
self::COUNTRY_CODE => [8, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12],
344+
self::COUNTRY_NAME => [8, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12],
345+
self::REGION_NAME => [0, 0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16],
346+
self::CITY_NAME => [0, 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20],
347+
self::ISP => [0, 0, 0, 24, 24, 24, 24, 24, 24, 24, 24, 24],
348+
self::PROXY_TYPE => [0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8],
349+
self::DOMAIN => [0, 0, 0, 0, 28, 28, 28, 28, 28, 28, 28, 28],
350+
self::USAGE_TYPE => [0, 0, 0, 0, 0, 32, 32, 32, 32, 32, 32, 32],
351+
self::ASN => [0, 0, 0, 0, 0, 0, 36, 36, 36, 36, 36, 36],
352+
self::_AS => [0, 0, 0, 0, 0, 0, 40, 40, 40, 40, 40, 40],
353+
self::LAST_SEEN => [0, 0, 0, 0, 0, 0, 0, 44, 44, 44, 44, 44],
354+
self::THREAT => [0, 0, 0, 0, 0, 0, 0, 0, 48, 48, 48, 48],
355+
self::PROVIDER => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 52, 52],
356+
self::FRAUD_SCORE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 56],
357+
];
350358

351359
/**
352360
* Column name mapping.
@@ -368,6 +376,7 @@ class Database
368376
self::LAST_SEEN => 'lastSeen',
369377
self::THREAT => 'threat',
370378
self::PROVIDER => 'provider',
379+
self::FRAUD_SCORE => 'fraudScore',
371380
self::IP_ADDRESS => 'ipAddress',
372381
self::IP_VERSION => 'ipVersion',
373382
self::IP_NUMBER => 'ipNumber',
@@ -380,6 +389,7 @@ class Database
380389
*/
381390
private $databases = [
382391
// IPv4 databases
392+
'IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER-FRAUDSCORE',
383393
'IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER',
384394
'IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL',
385395
'IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT',
@@ -393,6 +403,7 @@ class Database
393403
'IP2PROXY-IP-COUNTRY',
394404

395405
// IPv6 databases
406+
'IPV6-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER-FRAUDSCORE',
396407
'IPV6-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER',
397408
'IPV6-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL',
398409
'IPV6-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT',
@@ -670,19 +681,19 @@ public function close()
670681
{
671682
switch ($this->mode) {
672683
case self::FILE_IO:
673-
// free the file pointer
674-
if ($this->resource !== false) {
675-
fclose($this->resource);
676-
$this->resource = false;
677-
}
678-
break;
684+
// free the file pointer
685+
if ($this->resource !== false) {
686+
fclose($this->resource);
687+
$this->resource = false;
688+
}
689+
break;
679690
case self::SHARED_MEMORY:
680-
// detach from the memory segment
681-
if ($this->resource !== false) {
682-
shmop_close($this->resource);
683-
$this->resource = false;
684-
}
685-
break;
691+
// detach from the memory segment
692+
if ($this->resource !== false) {
693+
shmop_close($this->resource);
694+
$this->resource = false;
695+
}
696+
break;
686697
}
687698
}
688699

@@ -766,6 +777,7 @@ public function lookup($ip, $fields = null, $asNamed = true)
766777
$ifields[] = self::LAST_SEEN;
767778
$ifields[] = self::THREAT;
768779
$ifields[] = self::PROVIDER;
780+
$ifields[] = self::FRAUD_SCORE;
769781
$ifields[] = self::COUNTRY;
770782
$ifields[] = self::IP_ADDRESS;
771783
$ifields[] = self::IP_VERSION;
@@ -790,6 +802,7 @@ public function lookup($ip, $fields = null, $asNamed = true)
790802
self::LAST_SEEN => false,
791803
self::THREAT => false,
792804
self::PROVIDER => false,
805+
self::FRAUD_SCORE => false,
793806
self::COUNTRY => false,
794807
self::IP_ADDRESS => false,
795808
self::IP_VERSION => false,
@@ -928,6 +941,13 @@ public function lookup($ip, $fields = null, $asNamed = true)
928941
}
929942
break;
930943

944+
case self::FRAUD_SCORE:
945+
if (!$done[self::FRAUD_SCORE]) {
946+
$results[self::FRAUD_SCORE] = $this->readFraudScore($pointer);
947+
$done[self::FRAUD_SCORE] = true;
948+
}
949+
break;
950+
931951
case self::IP_ADDRESS:
932952
if (!$done[self::IP_ADDRESS]) {
933953
$results[self::IP_ADDRESS] = $ip;
@@ -1063,12 +1083,12 @@ private function getMemoryLimit()
10631083
} else {
10641084
// Deal with shorthand bytes
10651085
switch (strtoupper(substr($limit, -1))) {
1066-
case 'G': $value *= 1024;
1067-
// no break
1068-
case 'M': $value *= 1024;
1069-
// no break
1070-
case 'K': $value *= 1024;
1071-
}
1086+
case 'G': $value *= 1024;
1087+
// no break
1088+
case 'M': $value *= 1024;
1089+
// no break
1090+
case 'K': $value *= 1024;
1091+
}
10721092
}
10731093
$this->memoryLimit = $value;
10741094
}
@@ -1264,7 +1284,7 @@ private function bcBin2Dec($data)
12641284
unpack('V', substr($data, 8, 4)),
12651285
unpack('V', substr($data, 4, 4)),
12661286
unpack('V', substr($data, 0, 4)),
1267-
];
1287+
];
12681288

12691289
foreach ($parts as &$part) {
12701290
if ($part[1] < 0) {
@@ -1308,17 +1328,17 @@ private function expand($ipv6)
13081328
private function read($pos, $len)
13091329
{
13101330
switch ($this->mode) {
1311-
case self::SHARED_MEMORY:
1312-
return shmop_read($this->resource, $pos, $len);
1331+
case self::SHARED_MEMORY:
1332+
return shmop_read($this->resource, $pos, $len);
13131333

1314-
case self::MEMORY_CACHE:
1315-
return $data = substr($this->buffer[$this->resource], $pos, $len);
1334+
case self::MEMORY_CACHE:
1335+
return $data = substr($this->buffer[$this->resource], $pos, $len);
13161336

1317-
default:
1318-
fseek($this->resource, $pos, \SEEK_SET);
1337+
default:
1338+
fseek($this->resource, $pos, \SEEK_SET);
13191339

1320-
return fread($this->resource, $len);
1321-
}
1340+
return fread($this->resource, $len);
1341+
}
13221342
}
13231343

13241344
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1679,6 +1699,29 @@ private function readProvider($pointer)
16791699
return $provider;
16801700
}
16811701

1702+
/**
1703+
* High level function to fetch the Fraud score.
1704+
*
1705+
* @param int $pointer Position to read from, if false, return self::INVALID_IP_ADDRESS
1706+
*
1707+
* @return string
1708+
*/
1709+
private function readFraudScore($pointer)
1710+
{
1711+
if ($pointer === false) {
1712+
// Deal with invalid IPs
1713+
$fraudScore = self::INVALID_IP_ADDRESS;
1714+
} elseif ($this->columns[self::FRAUD_SCORE][$this->type] === 0) {
1715+
// If the field is not supported, return accordingly
1716+
$fraudScore = self::FIELD_NOT_SUPPORTED;
1717+
} else {
1718+
// Read the domain
1719+
$fraudScore = $this->readString($this->columns[self::FRAUD_SCORE][$this->type]);
1720+
}
1721+
1722+
return $fraudScore;
1723+
}
1724+
16821725
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16831726
// Binary search and support functions /////////////////////////////////////////////////////////////////////////////////////////////////
16841727
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1769,7 +1812,7 @@ private function binSearch($version, $ipNumber)
17691812
case 1:
17701813
$low = $mid + 1;
17711814
break;
1772-
}
1815+
}
17731816
}
17741817

17751818
return false;

0 commit comments

Comments
 (0)