php 用于获取基于IPAddress和SubnetMask的网络信息的类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 用于获取基于IPAddress和SubnetMask的网络信息的类相关的知识,希望对你有一定的参考价值。
class IpNetwork {
public $direccion_ip = null;
public $mascara = null;
public $red = null;
public $default_gw = null; //optional
public $broadcast = null;
public $number_of_hosts = null;
public $ip_inicio = null;
public $ip_fin = null;
public $tftp = null; //optional
public $ntp = null; //optional
public $dns = null; //optional
public function __construct($ip_address, $subnet_mask, $start = 1, $end = 1) {
$this->direccion_ip = $ip_address;
$this->mascara = $subnet_mask;
$this->calculate($start, $end);
}
public function calculate($start, $end) {
$numeric_ip = ip2long($this->direccion_ip);
$numeric_network_mask = ip2long($this->mascara);
$numeric_network_address = ($numeric_ip & $numeric_network_mask);
$numeric_broadcast = $numeric_network_address | (~$numeric_network_mask);
$this->red = long2ip($numeric_network_address);
$this->broadcast = long2ip($numeric_broadcast);
$this->ip_inicio = long2ip($numeric_network_address + $start);
$this->ip_fin = long2ip($numeric_broadcast - $end);
$this->default_gw = $this->direccion_ip; //optional
$this->tftp = $this->direccion_ip; //optional
$this->ntp = $this->direccion_ip; //optional
$this->dns = $this->direccion_ip; //optional
}
}
以上是关于php 用于获取基于IPAddress和SubnetMask的网络信息的类的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 PHP 获取服务器的公共 IP 地址?
PHP笔记-获取客户端IP及平台及浏览器
PHP检查IPAddress是不是是本地的
PHP中基于位掩码获取数组值
收到状态代码 400 no_key 的无效值“ipaddress”
Electron 应用程序导出为 Snap 时无法获取 ipaddress