查找子网中的所有IP [英] Find all IPs in a subnet

查看:273
本文介绍了查找子网中的所有IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我们的项目使用C ++开发代码的一部分,我的代码必须返回子网中所有可用IP的列表,所以我有这样的场景:


  1. 获取我的子网。


  2. 使用测试子网中的每个IP 循环,例如:

      for(int i = 0; i< 254; i ++)
    {
    testip(X,X,X,i);
    / *如果IP有效* /
    vectoriplist.push_back(X,X,X,i);
    }


查找子网我我想我会使用 IPnetwork实用程序,但我还有另一个问题,就是我如何测试IP是否有效在子网上。我尝试用 Boost.Asio的,但我无法找到任何东西。


解决方案
<我发现了一个解决方案:



我使用 coonect() getpeername() for循环中的函数。获取子网中的所有有效IP地址


I am developing a part of code using C++ for our project, my code must return a list of all available IPs in a subnet, so I have this scenario:

  1. Get my subnet.

  2. Test every IP in subnet using a for loop, e.g.:

    for (int i = 0; i < 254; i++)
    {
        testip(X, X, X, i);
        /* if IP is valid */
        vectoriplist.push_back(X, X, X, i);
    }
    

For find subnet I think I will use IPnetwork utility, but I still have another problem and it's how I can test if the IP is valid on the subnet. I try to use boost.asio, but I cannot find anything.

解决方案

i found a solution :

i use coonect() and getpeername() functions in for loop . to get all valid ip addresses in a subnet

这篇关于查找子网中的所有IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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