简体   繁体   English

将起始和终止IP范围转换为网络掩码

[英]Convert a start and end ip range to a net mask

Good morning, 早上好,

I am trying to get the subnet mask from a start and end ip in PHP. 我试图从PHP的开始和结束IP获取子网掩码。

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. 我搜索的所有内容均指CDIR并试图获取所有ip等信息,因此看来我正在尝试采用其他方式。

Anyone have any ideas? 有人有想法么?

This should get you what you want: 这应该给您您想要的:

$ip = "14.1.32.0"; 
$ip2 = "14.1.64.0";
echo long2ip(ip2long($ip) - ip2long($ip2));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM