获取两个IP地址之间的IP地址列表 [英] Getting IP address list between two IP addresses

查看:289
本文介绍了获取两个IP地址之间的IP地址列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个从用户获取来自IP地址和到IP地址的程序,并显示它们之间的IP地址列表。例如,如果用户给出10.0.0.1和10.0.0.5,那么我将显示这两者之间的五个IP地址。我想到的当前解决方案是:

I am writing a program that gets From IP address and To IP address from the user and displays the list of IP addresses between them. For example, if the user gives 10.0.0.1 and 10.0.0.5 then I will display the five IP addresses between these two. The current solution that is coming in my mind are:


  1. 获取所有IP地址的列表,然后查找生成的IP地址列表

  2. 使用嵌套循环

我应该采用什么解决方案(或建议更好)解)?对于第一个解决方案,IP地址表/列表的链接是什么?

What solution should I adopt between these (or suggest a better solution)? For the first solution, what is the link for IP address table/list?

JavaScript或Java方面的解决方案是什么?

What is the solution in terms of JavaScript or Java?

推荐答案

首先用分割IP地址。。从第一个IP地址开始,将第四个部分增加到255,然后将第一个部分加1,并将第四部分设置为1.直到达到IP地址。

First split the IP addresses with .. From the first IP address, start increasing the fourth part up to 255 and then add 1 to the third part and set the fourth one to 1. Until you reach the to IP address.


  • IP地址字节 - >位 - > Int32

  • 来自: 10.0.10.10 - > 00001010 00000000 00001010 00001010 - > 167774730

  • 收件人: 10.1.45.1 - > 00001010 00000001 00101101 00000001 - > 167849217

  • 从From到To开始计数,只检查不需要的字节 11111111 00000000

  • IP address bytes -> bits -> Int32
  • From: 10.0.10.10 -> 00001010 00000000 00001010 00001010 -> 167774730
  • To: 10.1.45.1 -> 00001010 00000001 00101101 00000001 -> 167849217
  • Start count from From to To and just check the unwanted bytes which is 11111111 and 00000000.

这就是全部。

这篇关于获取两个IP地址之间的IP地址列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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