1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
ipaddress.php
См. документацию.
1
<?php
2
9
10
namespace
Bitrix\Main\Web;
11
12
use Psr\Http\Message\UriInterface;
13
14
class
IpAddress
15
{
16
protected
$ip
;
17
21
public
function
__construct
(
$ip
)
22
{
23
$this->ip =
$ip
;
24
}
25
32
public
static
function
createByName
(
$name
)
33
{
34
$ip
= gethostbyname(
$name
);
35
return
new
static
(
$ip
);
36
}
37
44
public
static
function
createByUri
(UriInterface
$uri
)
45
{
46
return
static::createByName(
$uri
->getHost());
47
}
48
54
public
function
get
(): string
55
{
56
return
$this->ip
;
57
}
58
64
public
function
__toString
()
65
{
66
return
$this->
get
();
67
}
68
74
public
function
isPrivate
(): bool
75
{
76
return
(filter_var($this->ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) ===
false
);
77
}
78
84
public
function
isIPv4
(): bool
85
{
86
return
(filter_var($this->ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !==
false
);
87
}
88
95
public
function
matchRange
(
string
$cidr): bool
96
{
97
if
(str_contains($cidr,
'/'
))
98
{
99
[$subnet, $mask] = explode(
'/'
, $cidr);
100
}
101
else
102
{
103
$subnet = $cidr;
104
$mask = 32;
105
}
106
107
return
(ip2long($this->ip) & ~((1 << (32 - $mask)) - 1)) === ip2long($subnet);
108
}
109
114
public
function
toUnsigned
(): string
115
{
116
return
sprintf(
'%u'
, ip2long($this->ip));
117
}
118
124
public
function
toRange
(
int
$prefixLen): string
125
{
126
return
long2ip(ip2long($this->ip) & ~((1 << (32 - $prefixLen)) - 1)) .
'/'
. $prefixLen;
127
}
128
}
Bitrix\Main\Web\IpAddress
Определения
ipaddress.php:15
Bitrix\Main\Web\IpAddress\isIPv4
isIPv4()
Определения
ipaddress.php:84
Bitrix\Main\Web\IpAddress\createByName
static createByName($name)
Определения
ipaddress.php:32
Bitrix\Main\Web\IpAddress\isPrivate
isPrivate()
Определения
ipaddress.php:74
Bitrix\Main\Web\IpAddress\__toString
__toString()
Определения
ipaddress.php:64
Bitrix\Main\Web\IpAddress\$ip
$ip
Определения
ipaddress.php:16
Bitrix\Main\Web\IpAddress\toRange
toRange(int $prefixLen)
Определения
ipaddress.php:124
Bitrix\Main\Web\IpAddress\__construct
__construct($ip)
Определения
ipaddress.php:21
Bitrix\Main\Web\IpAddress\toUnsigned
toUnsigned()
Определения
ipaddress.php:114
Bitrix\Main\Web\IpAddress\createByUri
static createByUri(UriInterface $uri)
Определения
ipaddress.php:44
Bitrix\Main\Web\IpAddress\matchRange
matchRange(string $cidr)
Определения
ipaddress.php:95
$uri
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения
urlrewrite.php:61
$name
$name
Определения
menu_edit.php:35
bitrix
modules
main
lib
web
ipaddress.php
Создано системой
1.14.0