Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12420570
IP.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
IP.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Keruald\OmniTools\Network
;
use
InvalidArgumentException
;
abstract
class
IP
{
///
/// Helper methods
///
public
static
function
isIP
(
string
$ip
)
:
bool
{
return
self
::
isIPv4
(
$ip
)
||
self
::
isIPv6
(
$ip
);
}
public
static
function
isIPv4
(
string
$ip
)
:
bool
{
return
filter_var
(
$ip
,
FILTER_VALIDATE_IP
,
FILTER_FLAG_IPV4
)
!==
false
;
}
public
static
function
isIPv6
(
string
$ip
)
:
bool
{
return
filter_var
(
$ip
,
FILTER_VALIDATE_IP
,
FILTER_FLAG_IPV6
)
!==
false
;
}
public
static
function
isLoopback
(
string
$ip
)
:
bool
{
$ranges
=
IPRange
::
getLoopbackRanges
();
foreach
(
$ranges
as
$range
)
{
if
(
$range
->
contains
(
$ip
))
{
return
true
;
}
}
return
false
;
}
///
/// Constructor
///
public
static
function
from
(
string
$ip
)
:
IP
{
if
(
self
::
isIPv4
(
$ip
))
{
return
new
IPv4
(
$ip
);
}
if
(
self
::
isIPv6
(
$ip
))
{
$ipv6
=
new
IPv6
(
$ip
);
$ipv6
->
normalize
();
return
$ipv6
;
}
throw
new
InvalidArgumentException
;
}
public
abstract
function
__toString
()
:
string
;
public
abstract
function
getDomain
()
:
int
;
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Thu, Nov 6, 11:25 (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3128138
Default Alt Text
IP.php (1 KB)
Attached To
Mode
rKOT Keruald OmniTools
Attached
Detach File
Event Timeline
Log In to Comment