Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93039578
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
Mon, Nov 25, 18:15
Size
903 B
Mime Type
text/x-php
Expires
Wed, Nov 27, 18:15 (2 d)
Engine
blob
Format
Raw Data
Handle
22548723
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