Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92612962
PhutilCIDRList.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 22, 01:02
Size
903 B
Mime Type
text/x-php
Expires
Sun, Nov 24, 01:02 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22470910
Attached To
rPHU libphutil
PhutilCIDRList.php
View Options
<?php
/**
* List of CIDR notation IP blocks, like "172.30.0.0/16".
*
* This class is primarily useful for managing IP whitelists or blacklists.
* For example, you can check if an address is on a subnet like this:
*
* $whitelist = PhutilCIDRList::newList(array('172.30.0.0/16'));
* $ok = $whitelist->containsAddrsss('172.30.0.1');
*/
final
class
PhutilCIDRList
extends
Phobject
{
private
$blocks
;
private
function
__construct
()
{
// <private>
}
public
static
function
newList
(
array
$blocks
)
{
foreach
(
$blocks
as
$key
=>
$block
)
{
$blocks
[
$key
]
=
PhutilCIDRBlock
::
newBlock
(
$block
);
}
$obj
=
new
PhutilCIDRList
();
$obj
->
blocks
=
$blocks
;
return
$obj
;
}
public
function
containsAddress
(
$address
)
{
foreach
(
$this
->
blocks
as
$block
)
{
if
(
$block
->
containsAddress
(
$address
))
{
return
true
;
}
}
return
false
;
}
}
Event Timeline
Log In to Comment