将IP分为最大和最小 [英] Break an IP into maximum and minimum

查看:128
本文介绍了将IP分为最大和最小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,
我在想,因为我不知道如何开始.朝着正确方向的观点将不胜感激:).

说我有以下格式的两个IP,
ipv4-192.168.168.100/24
IPv6-2620:0:860:2 :://64

我想通过c#获取上述的最小和最大ip范围.它应该与两个ip版本兼容.请帮助我.我不知道该如何开始.

非常感谢.

Hey,
I was wondering cause i don''t know how to start on it. A point in the right direction would be much appreciated :) .

Say i have two ip''s in the following format,
Ipv4-192.168.168.100/24
IPv6-2620: 0:860:2::/64

I want to get he minimum and maximum ip range of the above via c#. It should be compatible with both the ip versions.please help me. I don''t know how to start on it..

thank you very much.

推荐答案

uint getMinHostRange(int maskLength){
  return 1; //0 is not allowed
}

uint getMaxHostRange(int maskLength){
  uint mask = 1;
  while(i=1;i<masklength;++i){>
    mask = mask<<1+1;
  }
  return mask-1;
}



ip地址无关紧要,因为正如我所说的IP今天使用类路由.



The ip address is not relevant because as I said IP uses classles routing today.


这篇关于将IP分为最大和最小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆