如何计算两个IP之间的主机数量? C# [英] How to calculate number of hosts between two ips? c#

查看:97
本文介绍了如何计算两个IP之间的主机数量? C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个ip:

1. 1.1.1.1
2. 4.4.4.4

显然,这只是一个例子,这是动态计算器

obviously this is just an example, this is a dynamic calculator

如果子网掩码不相关,我如何计算上述ips之间的主机数量?

how do i calculate number of hosts between said ips if subnet mask is irrelevant?

推荐答案

要计算(理论上的)IP地址的数量,您可以将每个IP地址转换为32位整数格式(实际上就是它的真正含义),那么这只是简单的减法即可:

To calculate the number of (theoretical) IP addresses you would convert each IP address to it's 32 bit integer format (which is actually what it really is), then it's just a matter of simple subtraction:

1.1.1.1 = 0x01010101 = 16843009
4.4.4.4 = 0x04040404 = 67372036

不包括起始地址和结束地址的地址数:

Number of addresses excluding the start and end address:

67372036 - 16843009 - 1 = 50529026

地址数,包括开始和结束地址:

Number of addresses including the start and end address:

67372036 - 16843009 + 1 = 50529028

实际可用地址的数量会少一些。通常每个C范围中的一些地址都用于网关(路由器)之类的东西。

The number of actual usable addresses would be somewhat lower. Normally a few addresses in each C range is reserved for things like the gateway (router).

这篇关于如何计算两个IP之间的主机数量? C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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