拿一个ip并获得子网掩码,& CIDR

时间:2016-02-11 23:35:56

标签: networking ip subnet

我发现这个网站计算器解释了ip class(A,B,C,D,E)以及如何获取子网掩码,他不太清楚如何配置数量节点(用于计算主机位数的公式),他说'由于您知道节点的数量,因此您需要找到' n'。' ;得到2 ^ 6 - / 26。我不明白他如何使用64个节点。

subnet calculator

First depict the ip address in binary. Take 61.246.19.18 and convert to binary:

ip address: 00111101.11110110.00010011.00010010
First we determine what class of address it is:

If the first bit is 0 it is a Class A address If the first two bits are 10 it is a Class B address If the first three bits are 110 it is a Class C address If the first four bits are 1110 it is a Class D multicast address If the first four bits are 1111 it is a Class E experimental address

Your example is a Class A address. The default subnet mask for a Class A address is:

subnet mask: 11111111.00000000.00000000.00000000
The formula for figuring out the number of 'host' bits in a subnet mask is
2^n=(number of nodes ) (2^n means '2' to the power of 'n')
Since you know the number of nodes, you need to find 'n'.

Because you want 64 node(s), you want to leave 6 - '0' bits in the subnet mask since 64 = 2 ^ 6.
This will give you the following subnet mask:

subnet mask: 11111111.11111111.11111111.11000000
Which is referred to as /26 or in dotted decimal notation as 255.255.255.192  

我搜索过的大多数主题都说无法从给定的IP地址中找到/ cidr范围,但是这个网页子网计算器确实从给定的ip创建范围。我理解如何将ip转换为二进制并获得类子网掩码,但他没有使用这些来获得他的64位主机位结果,我认为他在转换类子网掩码后跳过了如何配置主机位。

还有很多在线计算器还要求你手动输入cidr范围,以获得ip的范围等等。这似乎是我能找到的唯一能够创建ip信息的计算器示例给定的IP地址。

我需要从给定的ip收集ip范围来阻止来自我网站的用户注册,如果他们因为退款原因已被禁止。所以我想创建一个php脚本来将新用户ip与被禁用的ip列表范围进行比较。这将决定他们是否通过创建新帐户禁止逃避。

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

从网络角度来看:

/ 26表示26个网络位和6个主机位。

为简化起见,您可以使用此公式

Network Bits (NB) + Host Bits (HB) = 32

/26 represents netmask or we can say NB= 26, which means HB = 32-26 = 6

这意味着您将在单个子网中拥有64个节点(2 ^ HB => 2 ^ 6 = 64)。

这个简单的CIDR Tutorial可能会有所帮助。

您还可以从给定的IP中识别最小的网络大小。 将这些IP转换为二进制。然后计算IP中的公共位,即网络位,根据这些位可以找到子网掩码。

例如 我们说我们有2个IP 192.168.24.12和192.168.24.76

  

192.168.24.12二进制 11000000 10101000 00011000 0 0001100

     

192.168.24.76二进制 11000000 10101000 00011000 0 1001100

Here first 25 bits are common bits. Which means these IPs can be from /25 subnet.

答案 1 :(得分:0)

在此示例中,节点数是您自己的输入。这就是说,我有64台机器,我需要在我的给定网络上为它们找到足够的IP。然后使用此计算方法确定子网掩码和IP分配。

但这篇文章很难解释这一点。