1441 |
ariadna |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace GeoIp2\Record;
|
|
|
6 |
|
|
|
7 |
use GeoIp2\Util;
|
|
|
8 |
|
|
|
9 |
/**
|
|
|
10 |
* Contains data for the traits record associated with an IP address.
|
|
|
11 |
*
|
|
|
12 |
* This record is returned by all location services and databases.
|
|
|
13 |
*/
|
|
|
14 |
class Traits implements \JsonSerializable
|
|
|
15 |
{
|
|
|
16 |
/**
|
|
|
17 |
* @var int|null The autonomous system number
|
|
|
18 |
* associated with the IP address. See
|
|
|
19 |
* https://en.wikipedia.org/wiki/Autonomous_system_(Internet%29. This attribute
|
|
|
20 |
* is only available from the City Plus and Insights web services and the
|
|
|
21 |
* GeoIP2 Enterprise database.
|
|
|
22 |
*/
|
|
|
23 |
public readonly ?int $autonomousSystemNumber;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* @var string|null The organization
|
|
|
27 |
* associated with the registered autonomous system number for the IP address.
|
|
|
28 |
* See https://en.wikipedia.org/wiki/Autonomous_system_(Internet%29. This
|
|
|
29 |
* attribute is only available from the City Plus and Insights web services and
|
|
|
30 |
* the GeoIP2 Enterprise database.
|
|
|
31 |
*/
|
|
|
32 |
public readonly ?string $autonomousSystemOrganization;
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* @var string|null The connection type may take the
|
|
|
36 |
* following values: "Dialup", "Cable/DSL", "Corporate", "Cellular", and
|
|
|
37 |
* "Satellite". Additional values may be added in the future. This attribute is
|
|
|
38 |
* only available from the City Plus and Insights web services and the GeoIP2
|
|
|
39 |
* Enterprise database.
|
|
|
40 |
*/
|
|
|
41 |
public readonly ?string $connectionType;
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* @var string|null The second level domain associated with the
|
|
|
45 |
* IP address. This will be something like "example.com" or "example.co.uk",
|
|
|
46 |
* not "foo.example.com". This attribute is only available from the
|
|
|
47 |
* City Plus and Insights web services and the GeoIP2 Enterprise
|
|
|
48 |
* database.
|
|
|
49 |
*/
|
|
|
50 |
public readonly ?string $domain;
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* @var string|null The IP address that the data in the model
|
|
|
54 |
* is for. If you performed a "me" lookup against the web service, this
|
|
|
55 |
* will be the externally routable IP address for the system the code is
|
|
|
56 |
* running on. If the system is behind a NAT, this may differ from the IP
|
|
|
57 |
* address locally assigned to it. This attribute is returned by all end
|
|
|
58 |
* points.
|
|
|
59 |
*/
|
|
|
60 |
public readonly ?string $ipAddress;
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* @var bool This is true if the IP address belongs to
|
|
|
64 |
* any sort of anonymous network. This property is only available from GeoIP2
|
|
|
65 |
* Insights.
|
|
|
66 |
*/
|
|
|
67 |
public readonly bool $isAnonymous;
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* @var bool This is true if the IP address is
|
|
|
71 |
* registered to an anonymous VPN provider. If a VPN provider does not register
|
|
|
72 |
* subnets under names associated with them, we will likely only flag their IP
|
|
|
73 |
* ranges using the isHostingProvider property. This property is only available
|
|
|
74 |
* from GeoIP2 Insights.
|
|
|
75 |
*/
|
|
|
76 |
public readonly bool $isAnonymousVpn;
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* @var bool This is true if the IP address belongs to an [anycast
|
|
|
80 |
* network](https://en.wikipedia.org/wiki/Anycast). This property is not
|
|
|
81 |
* available from GeoLite databases or web services.
|
|
|
82 |
*/
|
|
|
83 |
public readonly bool $isAnycast;
|
|
|
84 |
|
|
|
85 |
/**
|
|
|
86 |
* @var bool This is true if the IP address belongs
|
|
|
87 |
* to a hosting or VPN provider (see description of isAnonymousVpn property).
|
|
|
88 |
* This property is only available from GeoIP2 Insights.
|
|
|
89 |
*/
|
|
|
90 |
public readonly bool $isHostingProvider;
|
|
|
91 |
|
|
|
92 |
/**
|
|
|
93 |
* @var bool This attribute is true if MaxMind
|
|
|
94 |
* believes this IP address to be a legitimate proxy, such as an internal
|
|
|
95 |
* VPN used by a corporation. This attribute is only available in the GeoIP2
|
|
|
96 |
* Enterprise database.
|
|
|
97 |
*/
|
|
|
98 |
public readonly bool $isLegitimateProxy;
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* @var bool This is true if the IP address belongs to
|
|
|
102 |
* a public proxy. This property is only available from GeoIP2 Insights.
|
|
|
103 |
*/
|
|
|
104 |
public readonly bool $isPublicProxy;
|
|
|
105 |
|
|
|
106 |
/**
|
|
|
107 |
* @var bool This is true if the IP address is
|
|
|
108 |
* on a suspected anonymizing network and belongs to a residential ISP. This
|
|
|
109 |
* property is only available from GeoIP2 Insights.
|
|
|
110 |
*/
|
|
|
111 |
public readonly bool $isResidentialProxy;
|
|
|
112 |
|
|
|
113 |
/**
|
|
|
114 |
* @var bool This is true if the IP address is a Tor
|
|
|
115 |
* exit node. This property is only available from GeoIP2 Insights.
|
|
|
116 |
*/
|
|
|
117 |
public readonly bool $isTorExitNode;
|
|
|
118 |
|
|
|
119 |
/**
|
|
|
120 |
* @var string|null The name of the ISP associated with the IP
|
|
|
121 |
* address. This attribute is only available from the City Plus and Insights
|
|
|
122 |
* web services and the GeoIP2 Enterprise database.
|
|
|
123 |
*/
|
|
|
124 |
public readonly ?string $isp;
|
|
|
125 |
|
|
|
126 |
/**
|
|
|
127 |
* @var string|null The [mobile country code
|
|
|
128 |
* (MCC)](https://en.wikipedia.org/wiki/Mobile_country_code) associated with
|
|
|
129 |
* the IP address and ISP. This property is available from the City Plus and
|
|
|
130 |
* Insights web services and the GeoIP2 Enterprise database.
|
|
|
131 |
*/
|
|
|
132 |
public readonly ?string $mobileCountryCode;
|
|
|
133 |
|
|
|
134 |
/**
|
|
|
135 |
* @var string|null The [mobile network code
|
|
|
136 |
* (MNC)](https://en.wikipedia.org/wiki/Mobile_country_code) associated with
|
|
|
137 |
* the IP address and ISP. This property is available from the City Plus and
|
|
|
138 |
* Insights web services and the GeoIP2 Enterprise database.
|
|
|
139 |
*/
|
|
|
140 |
public readonly ?string $mobileNetworkCode;
|
|
|
141 |
|
|
|
142 |
/**
|
|
|
143 |
* @var string|null The network in CIDR notation associated with
|
|
|
144 |
* the record. In particular, this is the largest network where all of the
|
|
|
145 |
* fields besides $ipAddress have the same value.
|
|
|
146 |
*/
|
|
|
147 |
public readonly ?string $network;
|
|
|
148 |
|
|
|
149 |
/**
|
|
|
150 |
* @var string|null The name of the organization
|
|
|
151 |
* associated with the IP address. This attribute is only available from the
|
|
|
152 |
* City Plus and Insights web services and the GeoIP2 Enterprise database.
|
|
|
153 |
*/
|
|
|
154 |
public readonly ?string $organization;
|
|
|
155 |
|
|
|
156 |
/**
|
|
|
157 |
* @var float|null An indicator of how static or
|
|
|
158 |
* dynamic an IP address is. This property is only available from GeoIP2
|
|
|
159 |
* Insights.
|
|
|
160 |
*/
|
|
|
161 |
public readonly ?float $staticIpScore;
|
|
|
162 |
|
|
|
163 |
/**
|
|
|
164 |
* @var int|null The estimated number of users sharing
|
|
|
165 |
* the IP/network during the past 24 hours. For IPv4, the count is for the
|
|
|
166 |
* individual IP. For IPv6, the count is for the /64 network. This property is
|
|
|
167 |
* only available from GeoIP2 Insights.
|
|
|
168 |
*/
|
|
|
169 |
public readonly ?int $userCount;
|
|
|
170 |
|
|
|
171 |
/**
|
|
|
172 |
* @var string|null <p>The user type associated with the IP
|
|
|
173 |
* address. This can be one of the following values:</p>
|
|
|
174 |
* <ul>
|
|
|
175 |
* <li>business
|
|
|
176 |
* <li>cafe
|
|
|
177 |
* <li>cellular
|
|
|
178 |
* <li>college
|
|
|
179 |
* <li>consumer_privacy_network
|
|
|
180 |
* <li>content_delivery_network
|
|
|
181 |
* <li>dialup
|
|
|
182 |
* <li>government
|
|
|
183 |
* <li>hosting
|
|
|
184 |
* <li>library
|
|
|
185 |
* <li>military
|
|
|
186 |
* <li>residential
|
|
|
187 |
* <li>router
|
|
|
188 |
* <li>school
|
|
|
189 |
* <li>search_engine_spider
|
|
|
190 |
* <li>traveler
|
|
|
191 |
* </ul>
|
|
|
192 |
* <p>
|
|
|
193 |
* This attribute is only available from the Insights web service and the
|
|
|
194 |
* GeoIP2 Enterprise database.
|
|
|
195 |
* </p>
|
|
|
196 |
*/
|
|
|
197 |
public readonly ?string $userType;
|
|
|
198 |
|
|
|
199 |
/**
|
|
|
200 |
* @ignore
|
|
|
201 |
*
|
|
|
202 |
* @param array<string, mixed> $record
|
|
|
203 |
*/
|
|
|
204 |
public function __construct(array $record)
|
|
|
205 |
{
|
|
|
206 |
$this->autonomousSystemNumber = $record['autonomous_system_number'] ?? null;
|
|
|
207 |
$this->autonomousSystemOrganization = $record['autonomous_system_organization'] ?? null;
|
|
|
208 |
$this->connectionType = $record['connection_type'] ?? null;
|
|
|
209 |
$this->domain = $record['domain'] ?? null;
|
|
|
210 |
$this->ipAddress = $record['ip_address'] ?? null;
|
|
|
211 |
$this->isAnonymous = $record['is_anonymous'] ?? false;
|
|
|
212 |
$this->isAnonymousVpn = $record['is_anonymous_vpn'] ?? false;
|
|
|
213 |
$this->isAnycast = $record['is_anycast'] ?? false;
|
|
|
214 |
$this->isHostingProvider = $record['is_hosting_provider'] ?? false;
|
|
|
215 |
$this->isLegitimateProxy = $record['is_legitimate_proxy'] ?? false;
|
|
|
216 |
$this->isp = $record['isp'] ?? null;
|
|
|
217 |
$this->isPublicProxy = $record['is_public_proxy'] ?? false;
|
|
|
218 |
$this->isResidentialProxy = $record['is_residential_proxy'] ?? false;
|
|
|
219 |
$this->isTorExitNode = $record['is_tor_exit_node'] ?? false;
|
|
|
220 |
$this->mobileCountryCode = $record['mobile_country_code'] ?? null;
|
|
|
221 |
$this->mobileNetworkCode = $record['mobile_network_code'] ?? null;
|
|
|
222 |
$this->organization = $record['organization'] ?? null;
|
|
|
223 |
$this->staticIpScore = $record['static_ip_score'] ?? null;
|
|
|
224 |
$this->userCount = $record['user_count'] ?? null;
|
|
|
225 |
$this->userType = $record['user_type'] ?? null;
|
|
|
226 |
|
|
|
227 |
if (isset($record['network'])) {
|
|
|
228 |
$this->network = $record['network'];
|
|
|
229 |
} else {
|
|
|
230 |
$this->network = isset($record['prefix_len']) ? Util::cidr($this->ipAddress, $record['prefix_len']) : null;
|
|
|
231 |
}
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
/**
|
|
|
235 |
* @return array<string, mixed>
|
|
|
236 |
*/
|
|
|
237 |
public function jsonSerialize(): array
|
|
|
238 |
{
|
|
|
239 |
$js = [];
|
|
|
240 |
if ($this->autonomousSystemNumber !== null) {
|
|
|
241 |
$js['autonomous_system_number'] = $this->autonomousSystemNumber;
|
|
|
242 |
}
|
|
|
243 |
if ($this->autonomousSystemOrganization !== null) {
|
|
|
244 |
$js['autonomous_system_organization'] = $this->autonomousSystemOrganization;
|
|
|
245 |
}
|
|
|
246 |
if ($this->connectionType !== null) {
|
|
|
247 |
$js['connection_type'] = $this->connectionType;
|
|
|
248 |
}
|
|
|
249 |
if ($this->domain !== null) {
|
|
|
250 |
$js['domain'] = $this->domain;
|
|
|
251 |
}
|
|
|
252 |
if ($this->ipAddress !== null) {
|
|
|
253 |
$js['ip_address'] = $this->ipAddress;
|
|
|
254 |
}
|
|
|
255 |
if ($this->isAnonymous !== false) {
|
|
|
256 |
$js['is_anonymous'] = $this->isAnonymous;
|
|
|
257 |
}
|
|
|
258 |
if ($this->isAnonymousVpn !== false) {
|
|
|
259 |
$js['is_anonymous_vpn'] = $this->isAnonymousVpn;
|
|
|
260 |
}
|
|
|
261 |
if ($this->isAnycast !== false) {
|
|
|
262 |
$js['is_anycast'] = $this->isAnycast;
|
|
|
263 |
}
|
|
|
264 |
if ($this->isHostingProvider !== false) {
|
|
|
265 |
$js['is_hosting_provider'] = $this->isHostingProvider;
|
|
|
266 |
}
|
|
|
267 |
if ($this->isLegitimateProxy !== false) {
|
|
|
268 |
$js['is_legitimate_proxy'] = $this->isLegitimateProxy;
|
|
|
269 |
}
|
|
|
270 |
if ($this->isPublicProxy !== false) {
|
|
|
271 |
$js['is_public_proxy'] = $this->isPublicProxy;
|
|
|
272 |
}
|
|
|
273 |
if ($this->isResidentialProxy !== false) {
|
|
|
274 |
$js['is_residential_proxy'] = $this->isResidentialProxy;
|
|
|
275 |
}
|
|
|
276 |
if ($this->isTorExitNode !== false) {
|
|
|
277 |
$js['is_tor_exit_node'] = $this->isTorExitNode;
|
|
|
278 |
}
|
|
|
279 |
if ($this->isp !== null) {
|
|
|
280 |
$js['isp'] = $this->isp;
|
|
|
281 |
}
|
|
|
282 |
if ($this->mobileCountryCode !== null) {
|
|
|
283 |
$js['mobile_country_code'] = $this->mobileCountryCode;
|
|
|
284 |
}
|
|
|
285 |
if ($this->mobileNetworkCode !== null) {
|
|
|
286 |
$js['mobile_network_code'] = $this->mobileNetworkCode;
|
|
|
287 |
}
|
|
|
288 |
if ($this->network !== null) {
|
|
|
289 |
$js['network'] = $this->network;
|
|
|
290 |
}
|
|
|
291 |
if ($this->organization !== null) {
|
|
|
292 |
$js['organization'] = $this->organization;
|
|
|
293 |
}
|
|
|
294 |
if ($this->staticIpScore !== null) {
|
|
|
295 |
$js['static_ip_score'] = $this->staticIpScore;
|
|
|
296 |
}
|
|
|
297 |
if ($this->userCount !== null) {
|
|
|
298 |
$js['user_count'] = $this->userCount;
|
|
|
299 |
}
|
|
|
300 |
if ($this->userType !== null) {
|
|
|
301 |
$js['user_type'] = $this->userType;
|
|
|
302 |
}
|
|
|
303 |
|
|
|
304 |
return $js;
|
|
|
305 |
}
|
|
|
306 |
}
|