【问题标题】:How to check if IPv6 is in between Two range of 2 (min and max) IPv6 addresses如何检查 IPv6 是否介于 2 个(最小和最大)IPv6 地址的两个范围之间
【发布时间】:2019-12-06 17:28:46
【问题描述】:

我有这个适用于 IPv4 地址的功能:

 # We need to be able to check if an ip_address in a particular range
protected function ipInRange($lower_range_ip_address, $upper_range_ip_address, $needle_ip_address)
{
    # Get the numeric reprisentation of the IP Address with IP2long
    $min    = ip2long($lower_range_ip_address);
    $max    = ip2long($upper_range_ip_address);
    $needle = ip2long($needle_ip_address);

    # Then it's as simple as checking whether the needle falls between the lower and upper ranges
    return (($needle >= $min) AND ($needle <= $max));
}   

如何将 IPv6 地址转换为工作? 谢谢

【问题讨论】:

    标签: php laravel-5 ip ip-address


    【解决方案1】:

    这应该对你有用..

    注意 ipInIPv6Range 函数名称更改。

    protected function ipInIPv6Range($startIP,$endIP,$ip){
      if(inet_pton($ip)>=inet_pton($startIP) && inet_pton($ip)<=inet_pton($endIP)) {
          return true;
       }
       return false;     
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-13
      • 2013-04-27
      • 1970-01-01
      • 2012-12-30
      • 2017-07-13
      • 2018-06-22
      • 2010-10-20
      • 2010-12-19
      相关资源
      最近更新 更多