dtqi87613 2013-08-12 22:20
浏览 367
已采纳

将开始和结束ip范围转换为网络掩码

Good morning,

I am trying to get the subnet mask from a start and end ip in PHP.

Eg;
14.1.32.0 and 14.1.64.0 is 255.255.224.0

But there doesn't seem to be any built in function for this? Everything I have searched refers to CDIR and trying to get all the ips etc so it seems I am trying to go the other way.

Anyone have any ideas?

  • 写回答

1条回答 默认 最新

  • drhs13583567608 2013-08-12 22:24
    关注

    This should get you what you want:

    $ip = "14.1.32.0"; 
    $ip2 = "14.1.64.0";
    echo long2ip(ip2long($ip) - ip2long($ip2));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥20 C语言用栈实现无向图邻接矩阵广度优先遍历
    • ¥15 C++代码报错问题,c++20协程
    • ¥15 c++图Djikstra算法求最短路径
    • ¥15 Linux操作系统中的,管道通信问题
    • ¥15 ansible tower 卡住
    • ¥15 等间距平面螺旋天线方程式
    • ¥15 通过链接访问,显示514或不是私密连接
    • ¥100 系统自动弹窗,键盘一接上就会
    • ¥50 股票交易系统设计(sql语言)
    • ¥15 调制识别中这几个数据集的文献分别是什么?