Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117751610
IP4Net.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
IP4Net.php
View Options
<?php
namespace
App
;
use
Illuminate\Database\Eloquent\Casts\Attribute
;
use
Illuminate\Database\Eloquent\Model
;
/**
* The eloquent definition of an IP network.
*
* @property string $country Country code
* @property int $id Network identifier
* @property string $net_broadcast Network broadcast address
* @property string $net_number Network address
* @property int $net_mask Network mask
* @property string $rir_name Network region label
* @property int $serial Serial number
*/
class
IP4Net
extends
Model
{
/** @var string Database table name */
protected
$table
=
"ip4nets"
;
/** @var list<string> The attributes that are mass assignable */
protected
$fillable
=
[
'rir_name'
,
'net_number'
,
'net_mask'
,
'net_broadcast'
,
'country'
,
'serial'
,
'created_at'
,
'updated_at'
,
];
/**
* Get IP network by IP address
*
* @param string $ip IP address
*
* @return ?self IP network record, Null if not found
*/
public
static
function
getNet
(
$ip
)
{
$ip
=
inet_pton
(
$ip
);
if
(!
$ip
)
{
return
null
;
}
return
static
::
where
(
'net_number'
,
'<='
,
$ip
)
->
where
(
'net_broadcast'
,
'>='
,
$ip
)
->
orderByRaw
(
'net_number, net_mask DESC'
)
->
first
();
}
/**
* net_number accessor. Internally we store IP addresses
* in a numeric form, outside they are human-readable.
*/
protected
function
netNumber
():
Attribute
{
return
Attribute
::
make
(
get
:
static
fn
(
$ip
)
=>
inet_ntop
(
$ip
),
set
:
static
fn
(
$ip
)
=>
inet_pton
(
$ip
),
);
}
/**
* net_broadcast accessor. Internally we store IP addresses
* in a numeric form, outside they are human-readable.
*/
protected
function
netBroadcast
():
Attribute
{
return
Attribute
::
make
(
get
:
static
fn
(
$ip
)
=>
inet_ntop
(
$ip
),
set
:
static
fn
(
$ip
)
=>
inet_pton
(
$ip
),
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Apr 4, 3:17 AM (1 d, 9 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
29/6e/09cb163421a38e3f9b01b6a1a4d4
Default Alt Text
IP4Net.php (2 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline