php和js怎么实现根据子网掩码和ip计算子网功能

  

小编给大家分享一下php和js怎么实现根据子网掩码和ip计算子网功能,希望大家阅读完这篇文章之后都有所收获、下面让我们一起去探讨吧!

具体如下:

<强> php

& lt; php ?   时间=美元ip  & # 39; 192.168.6.1& # 39;;   时间=美元mask  & # 39; 255.255.2.0& # 39;;   数组$ sub_net =,();//子网   $ ip_explode =,爆炸(& # 39;强生# 39;,,美元ip);   $ mask_explode =,爆炸(& # 39;强生# 39;,,面具美元);   foreach  (ip_explode 美元;as  key 美元;=祝辞,ip_num美元),{   美元才能sub_net [],=, (int) ip_num 美元;,,(int) mask_explode美元(美元关键);   }   $ sub_net =,内爆(& # 39;强生# 39;,,sub_net美元);   echo  sub_net美元;

运行结果:

192.168.2.0

<强> js

& lt; script>   var  ip =, & # 39; 192.168.6.1& # 39;;   var  mask =, & # 39; 255.255.255.0 # 39;;   var  sub_net =,[];//子网   var  ip_explode =, ip.split(& # 39; # 39;公司);   var  mask_explode =, mask.split(& # 39; # 39;公司);   console.log才能(& # 39;ip_explode=& # 39; + ip_explode);   console.log才能(& # 39;mask_explode=& # 39; + mask_explode);, for  (var 小姐:=,0,,num =, ip_explode.length;,小姐:& lt;, num;,我+ +),{   时间=c 才能;方法(ip_explode[我]),,,方法(mask_explode[我]);   console.log才能(& # 39;c=& # 39; + c);   sub_net.push才能(c);   }   时间=sub_net  sub_net.join(& # 39; # 39;公司);   console.log (sub_net);   & lt;/script>

运行结果:

 php和js怎么实现根据子网掩码和ip计算子网功能

看完了这篇文章,相信你对“php和js怎么实现根据子网掩码和ip计算子网功能”有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!

php和js怎么实现根据子网掩码和ip计算子网功能